Scientific classification is a great example of Classes and inheritance. A Dog is a Mammal, so it inherits things like fur, while a mammal is a vertebrate so they inherit spinal cords, etc. As you work down a dog has a spine because mammals do because vertebrates do. This is a “is a” class based inheritance example. I’m sure you’ll do composition based “has a” relationships.
@@LordTrashcanRulez If we're talking about something most mammals don't have, this "thing" doesn't belong to the class "mammal", but rather the sub-class itself. For example, a Platypus lays eggs. Laying eggs isn't a mammal trait, it's a Platypus trait, but the platypus subclass still inherits "produces milk", "warm blood", "Has hair *" from the Mammal class, like all other derived sub-classes. *All mammals have hair at least in some part of their bodies and/or at some point in their lives.
@@LordTrashcanRulez You should though. A good programer spends more time planing/researching than actually coding, exactly because of issues such as this. If you're one you know how seemingly little details you haven't foreseen can mess you up.
I’ve been searching for a video like this! I have experience with classes in Python but needed to understand how to implement them in Godot. Great explanation!
is there function overriding in Godot? can you have a function called hurt in the main class which is used in several places, then over ride that function in a sub class and have it changed on its calls in the main class?
Do classes have to be branched off of a scene? Or can they be their own scripts like singletons? I'm trying to make a deck class, but when I extend I don't have access to its variables
So when I try to remove the extends Node2D It just gives me an error. Not sure if it can be done and run the code from what I am testing. I am using Godot 4.2 currently. OVERALL though great tutorial! and super helpful!
On the topic of class_names though, I find them incredibly useful even if I don't inherit a class anywhere as it lets me reference or instantiate, say a Player Scene "as Player" like so: "var player: Player = player_scene.instantiate() as Player". Whenever I now type player. in this script I get full autocomplete for the Player class. I also can globally reference static functions the (in this case) player might have. Another nifty use case I found is that I could check in a signal like "on_body_entered(body)" if the "body is Player:" and then specify var player: Player = body as Player" for the same effect as above all the while completely skipping the need for a group check or similar things, so I have a sure fire, easy to read way of checking if the body (or whatever gets transmitted in the signal) is the thing I wanna do stuff with. Pretty sure there are more use cases but these come up so often for me.
this is so fckng useful. I'm trying to make a moba, and I was using loaded scenes to cast abilities and it was too buggy, the properties os one ability was inflencing others, as it was all just one ability. I think this would resolve
bro it's great you show pokemon, but they don't really work with subclasses. if you make a subclass of moves, it won't load them in the battle. I also wanna implement randomness like in pokemon stadium 2, no idea how to assign a template to a class.new() and call it from the game (something like if pokemon1.type1 == water, pokerandlist.remove("water"))
what? im sure the implementation of moves could 100% be done with subclasses. whether thats a good implementation or not is up for oop cracks to decide but i bet you the problem is behind the keyboard for this one.
Scientific classification is a great example of Classes and inheritance.
A Dog is a Mammal, so it inherits things like fur, while a mammal is a vertebrate so they inherit spinal cords, etc. As you work down a dog has a spine because mammals do because vertebrates do.
This is a “is a” class based inheritance example. I’m sure you’ll do composition based “has a” relationships.
This isn't actually easy to apply in practice, especially if you're working with the exceptions that don't have something most mammals have
@@LordTrashcanRulezthat’s why he mentioned composition
@@LordTrashcanRulez If we're talking about something most mammals don't have, this "thing" doesn't belong to the class "mammal", but rather the sub-class itself.
For example, a Platypus lays eggs. Laying eggs isn't a mammal trait, it's a Platypus trait, but the platypus subclass still inherits "produces milk", "warm blood", "Has hair *" from the Mammal class, like all other derived sub-classes.
*All mammals have hair at least in some part of their bodies and/or at some point in their lives.
@@somedudeAPS I'm NOT going to plan a class that deep in advance lmao.
@@LordTrashcanRulez You should though.
A good programer spends more time planing/researching than actually coding, exactly because of issues such as this.
If you're one you know how seemingly little details you haven't foreseen can mess you up.
I’ve been searching for a video like this! I have experience with classes in Python but needed to understand how to implement them in Godot. Great explanation!
I am a beginner, your video was very helpful to me.
Thank you! No intro, informative and to-the-point. Theory first, practice second. Subbed!
This is the most useful tutorial I've seen on the subject, how is this not the first result?😊
is there function overriding in Godot? can you have a function called hurt in the main class which is used in several places, then over ride that function in a sub class and have it changed on its calls in the main class?
thank you for this man. Do you have a website where you do tutorials via articles, or just youtube only.
I have a website, but currently most my teaching stuff is on TH-cam
Your videos are helping me so much!
Do classes have to be branched off of a scene? Or can they be their own scripts like singletons? I'm trying to make a deck class, but when I extend I don't have access to its variables
i think they have to extend at least a node. i havent tried to do it without it though.
So when I try to remove the extends Node2D
It just gives me an error.
Not sure if it can be done and run the code from what I am testing. I am using Godot 4.2 currently.
OVERALL though great tutorial! and super helpful!
I know this is a little late, but the main script needs to at least inherit a node-type
This is very helpful, thank you so much!
Really helpful, thank you!!
On the topic of class_names though, I find them incredibly useful even if I don't inherit a class anywhere as it lets me reference or instantiate, say a Player Scene "as Player" like so: "var player: Player = player_scene.instantiate() as Player".
Whenever I now type player. in this script I get full autocomplete for the Player class. I also can globally reference static functions the (in this case) player might have.
Another nifty use case I found is that I could check in a signal like "on_body_entered(body)" if the "body is Player:" and then specify var player: Player = body as Player" for the same effect as above all the while completely skipping the need for a group check or similar things, so I have a sure fire, easy to read way of checking if the body (or whatever gets transmitted in the signal) is the thing I wanna do stuff with.
Pretty sure there are more use cases but these come up so often for me.
Best guy on the internet
I was trying to create a state machine, but I didn't even know about classes =V
this is so fckng useful. I'm trying to make a moba, and I was using loaded scenes to cast abilities and it was too buggy, the properties os one ability was inflencing others, as it was all just one ability.
I think this would resolve
And how I create a virtual function? I want o override a func in the MainClass
Forget, I got it
bro it's great you show pokemon, but they don't really work with subclasses. if you make a subclass of moves, it won't load them in the battle. I also wanna implement randomness like in pokemon stadium 2, no idea how to assign a template to a class.new() and call it from the game (something like if pokemon1.type1 == water, pokerandlist.remove("water"))
what? im sure the implementation of moves could 100% be done with subclasses. whether thats a good implementation or not is up for oop cracks to decide but i bet you the problem is behind the keyboard for this one.
can we consider an octopus as an animal ? 😂
Would be better if you just showed completed classes in use then showed how they interacted, rather than empty scripts
Octopuses kicked out of animal world :D
thanks
🙏
NOICE
How is an octupus not an animal os my question
its a fishy
@@CodingQuests valid point