Hello. I’m at a point in my learning where I see potential to make a big mess and want some advice before that happens. Particularly, how to organize game systems like inventory, damage calculation, level variables (eg. locked doors -> remain unlocked even after the level scene is reloaded).
For Inventory (consumable items, weapons etc), what I’ve done so far that seems to work is create a global script called PlayerInventory, within it is a list of every item as a boolean variable to indicate if the player has it or not. So now when the player travels through different level scenes, their inventory is persistent and any upgrades remain. Seems to work so far.
But how would you go about doing this for a locked door in a level scene? One way is to tie it to a key, in the player inventory - if “key” == true, “locked” = false. Ok, fine. What about a wooden crate that has been destroyed by the player? How would you keep track of the crate’s destroyed state without it being tied to a “key item” in the PlayerInventory global script? Is the solution to create more global scripts, like “EnvironmentChanges”? What script should be responsible for remembering this and where should it live?
With regards to a damage calculation system, I think the high level question is similar- how to organize this? The path I’m going down looks like, “DamageManager” global script which handles the calculations and updates, meanwhile the player and enemy scenes have an “HP” node added, with the “hp” value variable set by the parent (the player or that specific enemy).
I’m looking for high-level ideas about how to make these things work together and to keep it as easy to maintain and organized as possible. More details and specifics are welcome, too. Thanks
I have an add-on that will help with game state like locked doors and stuff. You an find it in the Godot asset library as Game State Saver Plugin. If installed directly from the Godot editor, you’ll get a watered down demo with the add-on. But a more extensive example can be obtained by downloading the entire repository. That full demo has a locked door, switches that affect things in other level scenes and remember their state, and more.
As for a more flexible, extensible system for inventory I would look into custom resources. You can add things to the custom resource like an inventory texture, display name, and other info about an inventory item. Then you can use an exported property array and add the items as needed. You can even save the individual resources as resource files for easy reuse and updating later.
Now how to connect a custom resource to the save system is something I have not gotten around to doing, so I can’t say exactly how that would work right now.
Hope this helps!