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

  • Kelly
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    2 days ago

    Adding boolean variables for each item only scales so far, your inventory class has to know about all the items in the game.

    The next simplist implementation would be to change the inventory to a list of strings, then your level can check if the list contains a given string without the inventory code needing modification.

    If you need to track item counts (e.g. the player has 5 apples), then you can use a dictionary instead of a list. Then you can use the string as a key and store an integer as the value.