So, I'm making a simple clicker game and I want to know how I can make my variable constantly update between scripts. I already tried autoload but it doesn't seem to be the solution. Here's the code:
`extends Label
var counter: int = 0
var add: int = 0
var cost_increase: int = 1
func _process(delta):
Displays the score, multiplier, and cost.
text = str("Current Score: ",counter,"\nCurrent Multiplier: ",add,"\nCost to Upgrade: ", 20 * cost_increase)
func _on_button_pressed():
Each click adds to your score
counter += 1 + add
func _on_multiplier_pressed():
Detects if your score is equal or more than 20, then increases the score per click, otherwise it does nothing.
if counter >= 20 * cost_increase:
counter -= 20 * cost_increase
add += 1
cost_increase += 1
else:
pass`
I want the "add" variable to be constantly updated to another script:
`extends Button
@onready var Label1 = get_node("/root/GlobalLabel")
func _process(delta):
text = str("Score per Click: ", Label1.add)`
What I want to do is display the "add" variable as text on the button and label at the same time.
It does actually print the value of add, but it doesn't update after that. This is my first "game" I'm making, so apologies in advance for my dumbness lmao
Here what the game currently looks like, hope it helps:
I want the score per click button's value to be always the same as the current multiplier. The current multiplier updates but the score per click does not.