do i have to use classes?

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

I have many instances of an Object in my game who all point to the same .gd - script.

i think for myself i dont need to create a specific class to organise this because every instance uses the same script. in this script is determined if the instance is a boy or a girl, and their movement.

My question is: Do i have anny disadvantages by not using a self created spezific class?

:bust_in_silhouette: Reply From: gmaps

As long as the complexity of the code doesn’t affect your development it’s OK. Do not refactor your code unless you need to and you understand why you’re doing it. But there are few guidelines which you could follow. If the objects differ only by parameters and you have no duplicated functions (e.g. move_boy or move_girl) you don’t need multiple classes. If it does it would be more readable to have a script with common methods and parameters and to inherit it in another class which has special functions just for your class. E.g. script “human.gd” which is inherited by “boy.gd” and “girl.gd”.

Having multiple scripts for each object type with same functions is also considered a bad practice because you’ll have a lot of duplicated code. So what you tend to achieve with extending/inheriting classes is to have zero duplicated code and have classes define a single model/abstraction. So having a classes like BoyGirl.gd or CarMotorbike.gd is not advisable, it should be for example vehicle.gd, which is extended by either car or motorbike.

You can check extending scripts in Godot to see how it’s done.