Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Stopdot |
It appears that when I try to use a member function to change the value of a bool that is a member variable, the value of the bool inside of the _process() function does not change.
I put together a brief demo project to illustrate the problem that I am having.
The first script, “Scene_1.gd”, is attached to the root node which is a Spatial node.
The second script, “Flip Bool Button.gd”, is attached to a button. When the button is pushed, a member variable inside “Scene_1.gd” is called that is supposed to change the value of the bool, testBool, to true. Then, an “if” statement inside the _process function is supposed to start printing that the bool is true.
Scene_1.gd:
extends Spatial
var testBool = false
func _ready():
print("Scene_1 script, at _ready(), testBool = ", testBool)
func _process(delta):
if(self.testBool == true):
print("Scene_1 script, at _process, testBool = ", testBool)
func flipBool():
self.testBool = true
print("Scene_1 script, flipBool() called, testBool = ", testBool)
Flip Button Bool.gd:
extends Button
onready var root_script = load("res://Scene_1.gd").new()
func _pressed():
print("Flip Bool Button script, button pressed, testBool = ", root_script.testBool)
root_script.flipBool()
print("Flip Bool Button script, flipBool() called")
I would expect that when the button is pushed, the testBool becomes true and the “if” statement in the _process function starts printing that this is the case. Instead, when the button is pressed the following is output:
** Debug Process Started **
OpenGL ES 3.0 Renderer: Quadro M2200/PCIe/SSE2
Scene_1 script, at _ready(), testBool = False
Flip Bool Button script, button pressed, testBool = False
Scene_1 script, flipBool() called, testBool = True
Flip Bool Button script, flipBool() called
** Debug Process Stopped **
As you can see, the flipBool() function is called, and if the value of testBool is printed, it will show true. However, the if statement in the _process function never shows that testBool is true.
Why is this happening? Am I doing something wrong?
Thanks,