Having issues while storing datas in autoloads

Godot 4.2.1

Help Needed

Hi everyone ! I’m in need of help because I’m trying to implement a starcoin system in my game in the exact same way as the one found in New super mario bros U, but i’ve got many issues. But before entering into the details, i’m going to explain you the situation.

I’ve setted up a world map, that is responsible for entering levels, and 3 playable sublevels, following these three
videos by Gamedev Knight :
WorldMap level generation
Map movement
World map info display

I’m now tweaking the info system to show collected starcoins per level, using an array, so in a specific level, each of the 3 starcoins is added to that array when collected.

Since then, I encounter issues while the game is running.

When I store the starcoinArray, which handles collected starcoins, in the GameManager autoload script, and let’s say I enter Level 2 after beating level 1 and collecting all its starcoins, if i collect Level 2 starcoins, it will overwrite the starcoin amount of Level 1.

So instead of storing collected starcoins in the autoload script, i decided to do it in the RuntimeLevel script, which is attached to the level parent node. Here things work fine, except that if I play level 1 for instance and collect all starcoins, beat the level and return to world map, replay Level 1 and this time do not collect starcoins and finish the level, it will set my starcoinArray back to empty.
And I do not know how can i implement a system, like New SMB U, where when starcoins are collected and level is finished, starcoins are not effective anymore and if this same level is replayed, the amount of starcoins that Mario has remains unchanged.

Should I use resources to dynamically store level datas

Please, can someone help me ?

If you need more infos, i’ll provide it to you
Thanks !

You need to think about the lifetime of the variables that are storing your various coins.

When do they start? When do they end? When should they be cleared? How big should they get? Do you need to save them to a file and read them back again later?

Your question is to broad to answer, so have a think about what I said.

You’re right. I want my starcoins to be permanent, so that i can count them at the end of the game to unlock new things.