Hi, hope you've had a good day.
I'm new to Godot and a few days into my project I've noticed some strange behavior from the singleton (autoloaded script) I've made. For example:
In the Globlas.gd
export var life := 5
export var cooldown_time := 5
When I edit the value of life in the editor to 10 and print it:
func _ready():
print(life)
I get 10, but then I reduce life by 1 in the same Globals.gd script and print the new life value:
func change_life(num):
life += num
print(life)
I get 4, as tho the game forgot that the value was changed (and yes I've made sure that there's nowhere where I set life to 5 inbetween these two prints)
Also a similar thing happened to dictionaries:
onready var game_state = {
menu = 1,
play = 0
}
func _on_Start_button_up():
game_state.menu=0
game_state.play=1
print(game_state.play)
print is 1 but then in another script where I check game_state.play it sais that it's 0:
func _unhandled_input(event):
print(Globals.game_state.play)
if Globals.game_state.play == 1:
...
this prints 0, as tho nothing has changed even tho the print before showed that there was a change.
I think this might also be a problem when I try to reload the current scene, I have a dictionari in my Globals that contains the path of some nodes, in the debugger I see that dictionari being filled with new node id's but then when we get to another script it's as tho the dictionari is null. Basically for some reason the singleton didn't update for the rest of the game, as tho it isn't a singleton at all (and yes I did try re adding it to autoload)
Pleas help, this is extremely frustrating and I haven't really seen anyone else with this problem