Using files to store "evidence" in mystery game

Godot Version

godot 4

Question

I’m making a mystery game where you walk around and find evidence in one scene and then review it in another, and I’m trying to figure out what the best way to save that evidence across scenes is. my thought right now is to save the name of each piece of evidence you’ve collected to a text file that the evidence review scene could then access, but I am not good at this type of code, so if anyone has any ideas or reccomendations that would be appreciated.

It really depends on the volume and types of evidence that you are using in your game. Are all “evidence” the same, eg a sentence or two of text, or is it mixed like an image, text, audio etc?

How do you currently store your ‘evidence’, you refer to a name, is this all you need to store, and how many do you expect?

For instance you could store your evidence files in dictionary, something like this, where the index is the name of your piece of evidence:

var evidence_dictionary: Dictionary = {
     "Marys Job": {
             "description": "You discovered in a letter that Mary was a Doctor",
             "time_found": "07:58",
             "location_found": "Scene3",
      }
}

That dictionary could easily be saved in a file for reloading saved games. For ingame play you could just mark your evidence files (whatever format they are) as “gathered” or something similar, and when you need to list them simply search for all the evidences marked as such. Or if each piece of evidence is a scene, you could add it to a new group “gathered” to get them all with a node group search.

It really depends on the format and types of evidence you are referring to, but there are many ways to do this.

I appologize for the lack of specificity. I think some of the solutions presented here may work.

more specifically, my thought was that when you collect a piece of evidence, the game would save the name of that evidence or it’s condition(collected/not) in some form, and then in the actual evidence scene it would be able to reference that name or condition in order to instance or enable nodes within the scene correspopnding to the names of the evidence, essentially detatching the item pickup from the actual viewable object entirely.

I think saving these in the dictionary is a good idea, though I don’t know how that feature works. does it automatically save that so it can be re-accessed when you load the game? i’ll have to look at the docs but if you have any direction for research that could speed the process up, I’m all ears

reading the docs and this may be my new favorite data structure

1 Like

Dictionary doesn’t save your data to a file automatically, it is stored in local memory only and will be freed when you exit the game. But you can make the Dictionary be saved to a file and then loaded from it, using JSON class. It’s described in more detail here:

But if you need any more guidance - let me know.

1 Like

They are amazing! And fast too!

Top Tip:
When printing your dictionary for testing and seeing what’s in it etc, try this:

print(JSON.stringify(my_dictionary, "\t"))

So much easier to read!

1 Like