How I can do to use a variable of a node from another node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By XenoN
:warning: Old Version Published before Godot 3 was released.

enter image description here

enter image description here

enter image description here

enter image description here

So … how to edit the variable from one node to be modified on the other node? Help me pleasee

:bust_in_silhouette: Reply From: Warlaan

Godot is strictly object oriented. When you define a var it becomes part of the object that the script is attached to. So when you access pts_rest from within the first script you are looking for the pts_rest-value in the first RichTextLabel and when you are doing it from within the second one you won’t find it since that one doesn’t have a var called pts_rest.

You need to get a reference to the first RichTextLabel in order to access the variable. The easiest way to do so is to use get_node(). In your case that’s ok, since all nodes are part of the same scene.

By the way I would recommend moving the code into a script that is attached to the base node of the scene (the one called “TextureFrame”). After all you are programming a new complex control, not a collection of smart buttons. It’s not really the RichTextBox’s job to know how many points are left, that’s something the whole control should take care of.