Why the variable wont change

Godot Version

4.3

Question

I want to change a variable from a different script in the same scene.
First I write the class name of the script and the variable I want to change

classname.new().variablename = true

Here I want to change the variable to true. In the other script I want it to print smt hen the variable is true.

if variablename == true:
       print("true")

But its not printing that mean the variable dont change to true. How to fix it? Pls help

You should change the variable from the object that has the script attached and read it from the same object, like this:

var object_with_variable = get_node("path/to/node")

object_with_variable.variablename = true

if object_with_variable.variablename == true:
       print("true")

This should work fine

1 Like

Thanks! Its work!

Happy to hear that!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.