Dictionary, Class or resource

Godot Version

4.3

Question

So I’m starting a small project and as a newbie, I’m not sure which way to approach the challenge. I’m looking for a little advice before coding myself into a dead end only to start all over again.

  1. Imagine a 2D game that has a static map.
  2. On this map are 5 static locations where chests are going to be placed.
  3. Each chest may or may not require a key. Each chest could have contents or be empty.
  4. As the game designer, I have a number of pre-planned chest layouts. It contains a list of five chests; their contents, the key required and where they are to be placed. These preplanned layouts are required because random generated layouts could make the map unsolvable.
  5. So at the start of the game, the game will pick a random number which denotes which chest layout to use (prob start with 3 and then expand later).
  6. Now reading all the data in the selected chest layout, each chest (node?) is instantiated and populated with the chest X,Y position, what key is required and what is inside the chest
    =======
    My question is in regards to these preplanned chest layouts. What approach would be best. I already believe that I will have a scene which is a single chest and I will instantiate each chest from it.
    But how should I store the preplanned layouts. Should I create a dictionary with each entry having all the data for the five chests as sub-dictionaries? Should I create a resource?
    Yup, I’m not sure which way to turn. Thanks in advance for any help given.

I don’t think any of this will be a problem, but I prefer to use a dictionary, because:

  1. It’s flexible: Any changes I want or any new feature can be made by changing the data in a centralized dictionary and make sure it works right.
  2. Accessible to all game elements: Disk can be saved in a single file (with or without JSON format) so that each game element can know everything when it is downloaded, making it possible to update it with the new file without changing the game code.
  3. Highly structured: If I use classes and resources, it will create a complex network within the project that will be hard to ensure that they all work during development. With dictionary, all that needs to be done is assign values of specific keys to specific elements.
    One Recommendation:
  4. Use nested dictionaries or a list of dictionaries: If you put all the properties of everything in a dictionary, you’ll need distinct keys that are hard to access, so you can use a key as an item ID and set the value of the item to a dictionary of the other properties of that item, or work with an index instead of an ID, and so you can do this with an array…
1 Like