0 votes

I wanna get a component, variable or whatever it is called of a node from a script of another node.
Because I have a script on a RichTextLabel node and I have a Timer also, what I wanna do is get the "Wait Time" component of the Timer and change it in the script of the RichTextLabel.

I did this but it just doesn´t work:

func _on_Timer_timeout():
    if event.presed and event.scancode == KEY_KP_2 or KEY_K:
        get_node("Cronómetro").get("Wait Time")
in Engine by (12 points)
edited by

1 Answer

0 votes

Note: I edited your post to fix the code formatting. In future please try and format your code samples so they're easier to read.

It's hard to tell exactly how to fix your problem without knowing your tree structure, but I suspect it's due to having the node path wrong. The path you use in get_node() is relative to the current node. get_node("Cronómetro") only works if "Cronómetro" is the child of the current node. If it's a sibling, for example, it would be "../Cronómetro". See this tutorial for more info: https://docs.godotengine.org/en/latest/getting_started/step_by_step/scripting.html

Next, it's not clear what you want to do with the wait time. You can access a node's property directly by its name. For example:


would print the property. A list of a particular node type's properties, or "member variables" can be found in the docs. See Timer, for example.

by (20,481 points)

thanks for the advice! :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.