custom classes

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

When should I create my own classes? For example, I want to create a fireball spell, I create a scene and in the scene script I create an instance of that spell class to access the methods. Am I doing it right? What would be the right thing to do in my case?

:bust_in_silhouette: Reply From: ipdramon

In object oriented programming, you would at least create a class for everything that you want to appear in your program. The same goes for Godot. In Godot this is more appropiately created through the scene.
In the case of your firespell, you should create a scene based on a fitting node, maybe an Area(2D), Mesh, … and attach all specific parameters that it needs as sub nodes. If you find that you implement something you would like to reuse for let’s say an ice spell, then you should try to create a spell scene where you can put all the stuff a spell should have in your game, like attributes, maybe some general functions like cast(), hit() and so on that will be implemented in your specific fire/ice/whatever spells.
I would suggest you start with a specific fire spell scene and work your way up through refactoring. See what you copy from the fire spell scene to the next spells scene, that’s what you should implement/add in the more general spell scene.
If you already have a coding background, I suggest you look at this page Introduction of Object Oriented Programming - GeeksforGeeks
It gives a good introduction into the basics of object oriented programming. Just think of objects that they mention as the node instances you want to spawn of your spell and classes are the scenes in Godot.
Disclaimer: Of course you can also create classes in Godot, but I don’t think thats what you are looking for with a component you want to visualize in the game.