Thinking of RPG objects common structure

Hi, I’m new to defold and trying to grasp the concepts. I’ve started to think about objects structure, and need your advices on better approach.
I will explain my thought process, and you can tell me that I’m totally wrong :smiley:

Let’s start with the stats.go (or collection?) and inventory.go. They are two systems with their scripts, but affect each other. Equipped stuff changes some stats, and some stats limit what you can equip. So I want some common parent to control these common systems of a player and any enemy.
I can’t add one game object into another in a saved .go file, so I need a collection.
Let’s say it’s entity.collection where I add stats.go and inventory.go and some common entity.script to make some communication between these systems.
This collection I will add to player.collection and any enemyXYZ.collection.

Is it a correct way of doing things in defold, or I overengineer here? I feel like collections are maybe overkill, or it’s ok?

I see alternative here - create entity.go (not collection) and stats.script (not game object) + inventory.script. However, I feel the code will be more coupled - stats should know about the inventory and vice versa. I’d like to decouple them by adding this main manager.
Also, thinking about stats.go, I thought about composition of system. Like, I can have health.script attached, but adding mana.script is optional and could be added only to some enemies. The stats script will just check if there is mana attached and act accordingly.

I hope I expressed myself clear and happy to hear your advices. Maybe there are some good example projects to have an inspiration.
Thank you in advance!

1 Like

Hi and welcome to Defold! I think what you are describing is perfectly suited for a module. Read up on them here:

4 Likes

Thank you, Alex! I will learn about modules and think how can I aggregate my logic inside :+1:

2 Likes

That would be an overkill for the use case I think. My opinion on this is that as much as you can do in the code - do it in the code :smiley:

If you will add your “stats” as a module as Alex suggested, you can then require it into any script that needs them and you don’t need communication to access stats. For RPGs there will be a ton of data to handle, check out if beside of making a reasonable hierarchy, you can also think of you data as of a database :wink:

That’s what I’m trying to figure out for a looong time to make it right for my game :smiley:

3 Likes

Looks like the modules are the right way here. Thanks for sharing, Pawel!

3 Likes