So I'm currently developing a survival game. The problem I've run into is how to handle the data behind items. I want items to have unique metadata that can change throughout their lifetime, so I can't just tag a stick as "stick" and treat it the same as every other stick in the game. I also want to include class inheritance, so that if I change an element from a specific item group, like if I change some functionality behind the 'tool' class then all tools in my game will be updated.
I already have ideas behind how to handle the functionality behind this, but I'm really just struggling with how to organize class inheritance in the workspace. Having a module script for every sub-class and item is tedious, especially if some items inherit from more than one class. If I were to put all of the items in the same module script, that would be clunky to edit and I would probably struggle with overwriting variables constantly.
I think the closest comparison to what I'm trying to achieve is Minecraft, at least with how item data is tracked and handled by the game. If anyone has any suggestions or insight that would be greatly appreciated.
Based on the problems you've listed, I think that separating out the items' interfaces is a good solution. For example, you could have a general class for an item and another for an item interface. The item interface would contain functions that you want to expose to other parts of your program that are relevant to the behavior of the item. Of course, you would also be able to add multiple interfaces if you want to add more to the item. The interfaces would be part of the class itself and wouldn't change during the game.
The same idea can be applied to metadata. You can add components to an object during run time. For example, you can create a class called ItemDelegate
that acts as a component for an item. The idea is that the item class would call on certain methods of the delegate with the necessary arguments and the delegate would apply its special effects. For tools, you can create a sub-class called ToolDelegate
that has more methods for responding to activities to do with tools.
The main idea is to separate functionality of your items and connect them back up in ways that emphasize their relationship.
Ideas for this issue:
-Have values such as "description" and "damage" in the stick -Have a table somewhere store the data -Make a script to store data
That's all I got bro. Hope this helps.