Storing permanent values in singletons for instances

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By NeverEnd

Currently, I am trying to make collectibles for my metroidvania game. I have multiple “rooms” (scenes) connected by doors that load the new scene. I want to coins in my game to be collectible, and, as such, I want them to be queue_freed if they have already been collected. This is rather easy for a single coin, but I wanted to instance around 25 around the map. If the player switches through scenes, they would be able to recollect them. I could go about this by giving an export var for each coin as a sort of ID that adds its name to an array which keeps track of which coins have and have not been collected, but that may take a while manually and I was wondering if there is a more streamlined process I am currently not seeing. Thanks in advance!

:bust_in_silhouette: Reply From: JimArtificer

A list of object names saved in a singleton for the player is probably the simplest solution.

For the sake of comparison, another approach would be to persist each of the coin objects and have them remember if they have been collected or not to determine if they are visible/interactive.

When save file size was of utmost importance (older consoles) the solution here would be a series of constants that bit-shifted a boolean value so that your 25 coins could be stored in 25 bits of memory. The coin and the save/load would refer to the same constant and they’d be defined in a central location.