Best way to save a dictionary as a resource

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

For my game, I store information about the characters in dictionaries (things like name, text colour, paths to portraits and such). And I would like to have these dictionaries saved as resources. What is the best way to do that? Do I just create a new script for each char in the “characters” folder and declare a dictionary there? Or do I create a singular script called “characters” and declare the dictionaries of all characters? And what class should it the script(s) inherit? Or is there a way to save the data themselves as a resource?

:bust_in_silhouette: Reply From: BigTuna675

It depends on how you structure the code/data. Do you want to have one master dictionary, which contains information about all the characters? Or one small dictionary per character per file?

If it’s the former, you could just use a normal json style config file approach. The advantage of this is that it’s a little easier to edit/maintain since all of the information is in one spot. If you had 100’s of characters, I’m not sure if that would be an advantage or a disadvantage though.

If it’s the latter, one way that seems plausible would be to create a new resource, class name of “Characters” perhaps, and then you can use that Character resource as a template for each character you want to add. This has the advantage of one character per resource so less chance of spaghettifying something, but it might be harder to manage if you have 100’s of characters.

To set something like that up, you first make a new script that inherits from Resource. This is where you set up the template for your characters (characterName, stats, etc), and give it the class name of “Characters”. Then for each character, you add a new resource (right-click, new resource), which is named “Characters” since that is the class name. I hope that helps, cheers!