I’m worried that I might be misunderstanding something here, so please allow me to recap:
I currently have an inventory system that uses an array to list items the player has. There is an inventory cap, but the player can also drop things on the ground (a system that hasn’t yet been implemented, as I need to allow rooms to have their own respective inventories).
I also handle digestion using an array, in order to make sure things eaten by the player are digested one-by-one in the order they were eaten.
You’re suggesting that, instead of using arrays for both, I use generic objects; I.E instead of having $inventory[apple, apple]
you think I should have $inventory{apple:2}
. Doing it this way will prevent bugs caused by browser memory restrictions.
But, the downside of that is that once I get along to making the digestion mechanic, I’ll have to find out how to A: digest things in the order the player ate them in, and B: I’ll have to make a new variable for every food item in the game, so that I can then clone it and add it to the $digestion
object (e.g $digestion{ appleClone})
.
Alternatively, if I’m misunderstanding using an object for the digestion mechanic, you’re suggesting that I still use an array, but instead of using a nested array, I use object variables for each food item. I.E my current system looks like this: [[5,5,"apple"],[5,5,"apple"]
. You’re suggesting instead I use [$appleClone]
and then when digesting simply run $appleClone.hp-=
and $weight+=$appleClone.calories
.
Addition: Reading previous posts, you also suggested I use an array for the inventory, but instead of having the inventory read “an apple, an apple” I use a "Map
of name
to count
." You explain that the issue with this system is that, if there’s no limit (or a very high limit) on inventory space, this will bloat the save and cause local storage restrictions.
Addition #2: I may be wrong about you suggesting that my inventory should be an object. As the “other way” you suggested after the one I spoke about above, you say that instead of having an array with multiple entries (e.g [apple, apple, apple, pear]) I instead have an array of objects (e.g [$apple, $pear]), where each object variable has a count and a string for the display name.
Addition #3: You elaborate upon both of these ideas, as well as a few more on your post from the 22nd. Option 1 is to have an array with many entries of the same object; [apple, apple, apple]
. Option 2 is to do the same, but using…variables or something for some reason? Option 3 is to have an array where each entry is a different item; e.g [$apple, $cucumber]
where the number of an item is a property of said variable (I.E $inventory[$apple.count]
). Option 4 is similar, but instead of using an object variable, you’re suggesting I use a normal variable that stores a number (its count).
Addition #4: At the end of the post from the 22nd, you wrote the code $gut[index] = clone(apple)
. How would this work if I had eaten multiple apples/in between other foods? What I’m asking is, is each clone unique? And show do I address those clones; what are they named, and will they be actual global variables ($appleClone1, $appleClone 2)?
At the end of the day, my goal is this:
Inventory system:
- Ability to drop things in rooms (likely with a global cap). I can also replace this system with a chest at the home base that stores up to 300~ objects (or individual objects if I use variables in the inventory array). Though doing the latter will require that I edit battles to only allow drops in a special ending passage, before they’re lost forever (if you’ve ever played Darkest Dungeon, something like that).
- Player can carry an undetermined amount of items–likely a cap of 50, but starting at around 10.
- Easy to use, and preferably as little work and few variables as possible. (This is why I could consider doing something like an object for the inventory, and then simply setting/unsetting parameters whenever you pick or drop something; e.g pick up apple →
set $inventory.apple+=
; though this depends on me being able to initialize and set object parameters that don’t yet exist, instead of having to add them all to $inventory
beforehand.
Digestion system:
- Remembers order player ate things in
- Digests things one-by-one, deleting them once their HP reaches 0 and moving to the next item in line
- Again, as easy to use as possible, avoiding unnecessary clutter (e.g new object variables for EACH food item, that contains their hp and calories)
Please correct me where I’m wrong (or right), as I’d love to get this issue handled asap I apologise, for I’m very easily confused.