This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

So, I have two scripts, one has you tap a button, and upon tapping, will change a variable to "true", which is in another script. However, it isn't working as expected. The button is pressed and works correctly, but doesn't change the variable to true.

Scene tree: https://gyazo.com/c437b8d29f83640487cb8e571586fabc (The img HTML tag doesn't want to work.)
enter image description here

Tapping Script:

extends RichTextLabel

# Things that actually make the game work
var counter = 0
var timer = 0
var pressed = false

# Power Up Varibles
onready var powerSign = false

func _ready():
    # Tell what to do when the "Play" button is pressed.
    set_fixed_process(true)
    set_process_input(true)
    self.set_text("Money: $0")


func _fixed_process(delta):
    # Tap, Gain, Repeat...
    var press = Input.is_action_pressed("Press")

    if press and not pressed:
        print("Tap")
        counter += 1
        self.clear()
        self.add_text(str("Money: $", counter)) 
    pressed = press


    # Enough tapping, lets get rich!
func _on_Timer_timeout():

    # Open Sign (Add +$1 a second)
    if (powerSign == true):
        counter += 1
        self.clear()
        self.add_text(str("Money: $", counter))
        print("Added money (powerSign)")

Buy Button Script:

extends Button

# Variables
onready var powerSign = get_tree().get_root().get_node("World/Counter").get("powerSign")

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    pass


func _on_Button_pressed():

    if (powerSign == false):
        powerSign = true
        print("Button Pressed, it should work...")
in Engine by (164 points)
edited by

1 Answer

+1 vote
Best answer

boolean is not reference.
the powerSign variables are actually different on World/Counter and Button
you need to get a reference of Counter

extends Button

# Variables
onready var counter = get_node("/root/World/Counter")

func _ready():
    pass

func _on_Button_pressed():
    if (counter.powerSign == false):
        counter.powerSign = true
        print("Button Pressed, it should work...")
by (9,800 points)
selected by

Thanks for the quick reply!

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 Frequently asked questions and 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 [email protected] with your username.