SIngletone not updating

Godot Version

4.5

Question

I have a singletone called move_database. It contains the following dictionary:

var moves = {
	1:{"Name":"bite", "Damage":2, "Accuracy": 0.5, "Piercing": 1.5, "Effects":"bleed"},
	2:{"Name":"scratch", "Damage":1, "Accuracy": 2, "Piercing": 1, "Effects":"bleed"},
	3:{"Name":"sword_slash", "Damage":1, "Accuracy": 2, "Piercing": 1, "Effects":"none"},
	4:{"Name":"sword_thrust", "Damage":1, "Accuracy": 1, "Piercing": 2, "Effects":"none"},
	5:{"Name":"fireball", "Damage":1, "Accuracy": 3, "Piercing": 1, "Effects":"burn"},
	6:{"Name":"magic_missile", "Damage":2, "Accuracy": 0.5, "Piercing": 2.5, "Effects":"none"},
}

Recently, I’ve tried changing it to the following:

var moves = {
	1:{"Name":"Bite", "Damage":2, "Accuracy": 0.5, "Piercing": 1.5, "Effects":"bleed"},
	2:{"Name":"Scratch", "Damage":1, "Accuracy": 2, "Piercing": 1, "Effects":"bleed"},
	3:{"Name":"Sword Slash", "Damage":1, "Accuracy": 2, "Piercing": 1, "Effects":"none"},
	4:{"Name":"Sword Thrust", "Damage":1, "Accuracy": 1, "Piercing": 2, "Effects":"none"},
	5:{"Name":"Fireball", "Damage":1, "Accuracy": 3, "Piercing": 1, "Effects":"burn"},
	6:{"Name":"Magic Missile", "Damage":2, "Accuracy": 0.5, "Piercing": 2.5, "Effects":"none"},
}

As you see, the only thing changed were names of the abilities. And for some reason, all other scripts see old values (for example if I do something like print(move_database.moves[3][“Name”]) in a different script, it will output sword_slash instead of Sword Slash). I’ve tried restarting the game, restarting the engine, searching forums for solutions, but nothing worked. Please help, this problem has been tormenting me for three days at this point.

When you says singleton, do you mean the standard singleton pattern or the autoload of the game engine? if that’s the autoload, try to remove the node from there, close your engine and relaunch it. Statics works a bit weird some time and you need to relaunch the engine to see modifications.

If you use the single pattern, try to create another class with the same code and call your new class. For some reason, sometime class are kind of corrupted. It happened to me for a class, and I had to delete it and recreate it.

I mean that it’s a global autoload. And your solution did not work. I even tried deleting the script and creating a new one, but other scripts still see the old values.

If you created a new class, did you change its reference in the classes calling that singleton? For instance, if the singleton is MySingletonA, and you create MySingletonB, then all your classes calling MySingletonA.MyFunction(), must now call MySingletonB.MyFunction(), otherwise they will still call the old singleton and get the old values.

Yes I did. And I deleted the old singletone completely. So even if a script did try to call it, it would call nothing

strange… what about if you use the standard singleton pattern ? Do you have have the same behaviour ?

I just tried doing it and it just stopped working completely. Now it doesn’t even get the values from the singletone. Either I did something wrong, or something is wrong with the engine.

can you share the new class and how you call it in different classes ?
I know the engine has some issues with statics. Time to time, I have to restart it when I changes statics. Worst scenario, go back to a previous version of your project where everything is fine

I dont really understand what you mean by “new class”. I am still new to godot, so I am a bit dumb.

You’re not dumb, you’re still learning. It’s an important difference :wink:

Regarding your issue, it’s a guess but if you removed the old code, and it still seems to return the old value, to me that sounds like it gets the value from elsewhere. Is that possible?

1 Like

OH MY GOD YOU WERE RIGHT. I COMPLETELY FORGOT. I have a different autoload called heroes_database, which contains the information about different classes of characters. And it contains the moves that are available to certain class.

var heroes = {
1: {“name”: “Tank”, “hp”: 200, “damage”: 5, “speed”: -10, “cost”:1, “accuracy”: 10, “dodge”: 5, “block”: 30, “piercing”: 0, “interception”: 30, “moves”:[“sword_slash”, “sword_thrust”]},
2: {“name”:“Soldier”, “hp”:100, “damage”:10 , “speed”:0, “cost”:1, “accuracy”: 10, “dodge”: 15, “block”: 15, “piercing”: 15,“interception”:15, “moves”:[“sword_slash”, “sword_thrust”]},
3: {“name”:“Mage”, “hp”:50, “damage”:20 , “speed”:5, “cost”:1, “accuracy”: 10, “dodge”:30, “block”: 5, “piercing”: 30, “interception”: 0, “moves”:[“fireball”, “magic_missile”]}
}
I forgot that my other scripts were referncing this autoload instead of move_database to get the names of the abilities. I feel so dumb. Thank you.

2 Likes

Again, you’re not dumb, but learning. As are we all :raising_hands:

Glad I could help!

1 Like

Glad it could be solved ^^ Hope you will post some progress of your game. And no worries, we all have that tunnel effect.