0 votes

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?

Godot version 3.4.4
in Engine by (91 points)

1 Answer

0 votes

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!

by (177 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.