The way I prefer to do it is using dictionaries inside a table, so for example;
local Zombies = {
--["NAME"] = {DAMAGE,HEALTH,SPEED},
["ZombieNormal"] = {50,100,20},
}
Then to access the values you simply do
local Damage = Zombies["ZombieNormal"][1]
local Health = Zombies["ZombieNormal"][2]
local speed = Zombies["ZombieNormal"][3]
Thats just how I prefer to do it, it’s completely up to you.
It depends on how you want to set up your game. Both methods are relatively the same with minor differences (With arrays you can get the amount of items by simply doing #array, while with dictionaries you can index via dictionary[key]).
In your scenario, I think doing what MarcusTAndreas said would be easier and work better though.
Key rule: Don’t design a datastructure and make your code work around it, make your datastructure fit your needs
This means if you require fast lookup/removal of zombie stats by zombie then use first solution, but if you are just going to be iterating through all the zombies then do 2nd
Thanks for the OOP. I learned how to do it a while back on that exact thread but now my memory of it is foggy.
Never really got around to using it, I just can’t seem to set up my game to make it convenient for it. Kind of ironic because that’s part of why people use OOP lol.
I recommend how you did it the first way, using the model as the key for the zombie stats. You store less memory than your second method. Plus, indexing Zombies using the zombie model as the key is faster than traversing through the table until you find that an elements Zombie variable points to the particular zombie you’re looking for.
That’s just me though, and the difference in performance shouldn’t be noticeable in most cases.