How can I make a class for my items but they sort of vary?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jujumumu

I have items in my game and right now to define all the stats for them I use a dictionary. As there is more data to store the longer the dictionary gets and thats only for one item. Making a class called item would make everything a LOT easier but my items vary. Some are tools that do damage and have their own special stats while others may be blocks and have to store tilemap data. How can I do this? Or are classes not a thing in gdscript? I come from a python background.

:bust_in_silhouette: Reply From: blank

In a fact everything in Godot is a Class, every script you make is a Class, so this is actually an easy one, and has multiple solutions you can use.

Either make a reference class called item (unattached script), and make every other item class (script) extend that class. Or make a multipurpose class called item that has extend variables of various stats, and change those variables via editor for each item node you create.

Additionally you can set an item_type in the reference/description of your items, and when using an item from active slot, decide what to do for each item type e.g.:

if active_item.item_type == "potion": += 5
elif active_item.item_type == "block":
  var tile_position = world_to_map(get_global_mouse_position())
  tilemap.set_cell(tile_position.x, tile_position.y, active_item.tile)