I'm struggling to change a boolean variable

Godot Version

4.6

Question

I’m trying to change my variable through a get function, but it hasn’t worked thus far.

var value : bool 

func _ready() -> void:
	#print(_get_name())
	get_value()
	pass

func set_value( ) -> void:
	SaveManager.add_persistent_value( _get_name() )

func get_value() -> void:
	value = SaveManager.check_persistent_value( _get_name() )
	data_loaded.emit()

I’m trying to get a signal from my save global script.

func add_persistent_value(value : String) -> void:
	if check_persistent_value(value) == false:
		current_save.persistence.append(value)
	pass

func check_persistent_value( value :String)-> bool:
	var check = current_save.persistence as Array
	return check.has(value)

Any help is greatly appreciated.

How has it not worked? Do you get any errors? What do you expect to happen versus what really happens?

1 Like

The method has in the Array will return true or false. Does exists the entry? Can you add a print for *get_*name previous to the call? Can you print check array?

I’m trying to get my collectable objects to be persistent even when I change scenes, so when if the player comes back to the previous scene they can’t re collect the collectable. It simply does not “remember” which collectables have been collected between scenes. It doesn’t give me any kind of error.

I was using this video as reference, and I feel as though I understood what it was going for, but as far as I could troubleshoot, it seems like

var value : bool

in my persistent object scene is not changing when the player picks up the collectables, I thought it might have been my set and get functions, but I wasn’t able to figure out much on my own.

I normally don’t correct people’s typos and spelling mistakes. I produce more than a fair share of them myself, but I’ll make an exception here.

It’s boolEan, not boolian. It’s named after George Boole, hence: Boole-an.

1 Like

My bad.

If you are re loading the scene, is SaveManager a singleton? I think will be graet if you can explain a bit more the implementation, the snippets are not enough

I’ve decided to rework the entire save system on my game, I’ve come to realize that I didn’t fully understand how this system worked, and given this project is largely a learning the process and how to put a game together type of deal, I’ve ended up with deciding to re work it while trying to put the pieces together without too much reliance on a step by step tutorial. Thank you so much for your help and all, I really appreciate it!

1 Like