The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

I'm building a game with consumable items and such, and wanted to implement an item system, possibly a class based one, but I really don't know where to begin as godot doesn't have First-Class functions and the way that classes work is pretty weird.

Also, for some items i need to execute a function when something specific happens (like firing a gun, picking up money, being hit ect.)

Can someone explain me or at least give me some tips?

Godot version 3.4.2
in Engine by (13 points)

and the way that classes work is pretty weird.

What's exactly wrong with just Object - based classes?
This site works best with concrete questions. Do you have one?

1 Answer

0 votes

I based my item system almost entirely on dictionaries and I am glad with result. It was classic Hack and Slash game like Diablo, I am not sure if You are going for this kind of RPG weapon system ?
Anyways it worked like this : single nested dictionary was a complete database about one item. It contained data like mesh, shader, requirements, type, armature bone placement, cost, preview icon, and special effects. When item was rolled after mobs death, this dictionary was created partially randomly, based on serialized information about items, which was another dictionary kept in Autoload. Dictionary in Autoload was used to keep default data about all items (like what weapon has which mesh and damage it deals without magical affixes ). So these two dictionaries were working together to create final data about individual item. There was a "special effect" key in this dictionary, that determined different bahaviors of these items. I used Strings there to hold data about names of functions, that were supposed to be called for these specific objects ( like "shoot" or "defend" "oncrit" "backstab", as well as String paths components for magical effects to be loaded with those special items ( like "lifesteal", "fireaura") and they were next loaded dynamically in code ( load("res//effects" + name +".tscn"). So this is in general how individual scripted behaviors were handled. Special effects scenes and certain functions worked as additional agents extending original script , since all effects were iterated and called from their parent.

by (8,188 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.