Ok, after refactoring now its working correctly!
the persistent memory wasn't the problem, sorry for the confusion I am learning programming with Godot, this is my first game!! :)
The variable current_level is declared as an int on the singleton Vars which contains shared variables between scenes, the const last_level also is declared as an int.
After debugging on a label on the screen I notice that
if I print on the label (Vars.current_level is int) or (last_level is int) it returns true on the debug version, but on the release version it returns false.
This 3 functions were the problem, they worked fine on the debug version but not on the release:
func current_level_is_the_last():
return Vars.current_level == last_level
func set_next_level():
Vars.current_level += 1
func get_current_palette():
return get_palette(Vars.current_level)
After many tries, specially on the set_next_level() function, this is how they finally worked correctly on the release version.
func current_level_is_the_last():
return int(Vars.current_level) == int(last_level)
func set_next_level():
var curr_level:int = Vars.current_level
var next_level:int = curr_level + 1
Vars.current_level = next_level
func get_current_palette():
var curr_level: int = Vars.current_level
return get_palette(curr_level)
If would be nice to understand better what happened and how to avoid it on the future.
Any thoughts would be highly appreciated...
Thanks!!