- Edited
Hi.
This is my first post here. Sorry if am not doing it right.
How can I get updates from a static variable that gets changed/updated?
I know about "autoloads" and signals, but is it possible to check for/get updates without these methods?
I've done a simple example, three scenes with each script.
The scenes are: manager, button and label, where button and label is children of manager.
The manager shares a static variable between button and label.
class_name Manager
static var game_state : String = 'Play'
The button changes the "game_state" when its clicked
func _ready() -> void:
if self:
self.button_down.connect(change_game_state)
func change_game_state() -> void:
var new_state = ['Exit', 'Pause', 'Play'][randi_range(0, 2)]
Manager.game_state = new_state
And here is the problem! How can I make that when the static variable (game_state) is changed, that it also changes the label?
I thought it was possible to update the label with setters, but I just cant get it to work.
Label code:
var game_state : String = Manager.game_state :
set = set_game_state
func set_game_state(value: String) -> void:
if self:
self.text = value
I would really appreciate any help I can get.
Thanks in advance.