Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

Organizing a system where items have metadata?

Asked by 4 years ago

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.

2
If you find inheritance difficult to design around, have you heard of composition over inheritance? https://www.youtube.com/watch?v=wfMtDGfHWpA royaltoe 5144 — 4y
0
Thanks, that's actually a really helpful video. Composition is definitely the move for me since the scope of my project is pretty large. It's much more adaptable. aquathorn321 858 — 4y
0
also uh, never got around to reading your post i'll reply in a sec. royaltoe 5144 — 4y
0
" 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." royaltoe 5144 — 4y
View all comments (5 more)
0
what are you trying to change. If you want to change some variable for every instance, you can keep track of your instances in some module and loop thru the instances, updating them. royaltoe 5144 — 4y
0
but that seems a bit weird practice i feel like? what would need to be changed? can you give an example? royaltoe 5144 — 4y
0
im also looking forward to creating a survival game, answering this question could also help me, also i think you should try asking Soybeen, the creator of roblox survival game booga booga on how he did this, maybe he would be willing to help, maybe not, he works in roblox so proceed with caution, nobody wants to end up like DevVince did after copying his game Lord_WitherAlt 206 — 4y
0
@royaltoe If I were to change a mechanic behind tools, like how they interact with items, then I would need to manually update that for every tool in the game. aquathorn321 858 — 4y
0
@Lord_WitherAlt So with booga booga the items are all generic and don't carry any metadata. Every Log is treated the same. In contrast, I might have two iron pickaxes in my game with different durabilities, names or enchantments, etc. aquathorn321 858 — 4y

2 answers

Log in to vote
2
Answered by
RayCurse 1518 Moderation Voter
4 years ago

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.

Ad
Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
4 years ago

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.

Answer this question