Object-Oriented Programming (OOP) in Godot: Master Classes and Implementation Guide

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 พ.ย. 2024

ความคิดเห็น • 37

  • @Any_key404
    @Any_key404 ปีที่แล้ว +27

    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
      @LordTrashcanRulez 5 หลายเดือนก่อน

      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

    • @saber1776
      @saber1776 4 หลายเดือนก่อน

      @@LordTrashcanRulezthat’s why he mentioned composition

    • @somedudeAPS
      @somedudeAPS 28 วันที่ผ่านมา

      @@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
      @LordTrashcanRulez 28 วันที่ผ่านมา

      @@somedudeAPS I'm NOT going to plan a class that deep in advance lmao.

    • @somedudeAPS
      @somedudeAPS 28 วันที่ผ่านมา

      @@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.

  • @Nathan-fl6is
    @Nathan-fl6is หลายเดือนก่อน +2

    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!

  • @moxingames
    @moxingames ปีที่แล้ว +5

    I am a beginner, your video was very helpful to me.

  • @alexmcfly31415
    @alexmcfly31415 3 หลายเดือนก่อน +1

    Thank you! No intro, informative and to-the-point. Theory first, practice second. Subbed!

  • @pros_0143
    @pros_0143 2 หลายเดือนก่อน

    This is the most useful tutorial I've seen on the subject, how is this not the first result?😊

  • @SergioFernandezRD
    @SergioFernandezRD ชั่วโมงที่ผ่านมา

    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?

  • @i_know_truth_hurts
    @i_know_truth_hurts ปีที่แล้ว +4

    thank you for this man. Do you have a website where you do tutorials via articles, or just youtube only.

    • @CodingQuests
      @CodingQuests  ปีที่แล้ว +1

      I have a website, but currently most my teaching stuff is on TH-cam

  • @vinipossatto9586
    @vinipossatto9586 ปีที่แล้ว +2

    Your videos are helping me so much!

  • @LocdnessMomster
    @LocdnessMomster 11 หลายเดือนก่อน +2

    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

    • @CodingQuests
      @CodingQuests  11 หลายเดือนก่อน +2

      i think they have to extend at least a node. i havent tried to do it without it though.

  • @jaxterity
    @jaxterity 11 หลายเดือนก่อน +2

    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!

    • @SynfulWuulf
      @SynfulWuulf 9 หลายเดือนก่อน +1

      I know this is a little late, but the main script needs to at least inherit a node-type

  • @katerkarlodieprinzessin1059
    @katerkarlodieprinzessin1059 10 หลายเดือนก่อน +1

    This is very helpful, thank you so much!

  • @GreenLightDev
    @GreenLightDev 8 หลายเดือนก่อน +1

    Really helpful, thank you!!

  • @hiiambarney4489
    @hiiambarney4489 ปีที่แล้ว +1

    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.

  • @hassanjomaa4073
    @hassanjomaa4073 ปีที่แล้ว +4

    Best guy on the internet

  • @bradexoff7584
    @bradexoff7584 ปีที่แล้ว +3

    I was trying to create a state machine, but I didn't even know about classes =V

  • @tangerchef6662
    @tangerchef6662 10 หลายเดือนก่อน +1

    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

  • @nubsdre
    @nubsdre 10 หลายเดือนก่อน +1

    And how I create a virtual function? I want o override a func in the MainClass

    • @nubsdre
      @nubsdre 10 หลายเดือนก่อน

      Forget, I got it

  • @WizQuest64
    @WizQuest64 ปีที่แล้ว +2

    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"))

    • @hiiambarney4489
      @hiiambarney4489 ปีที่แล้ว

      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.

  • @alexxgg9208
    @alexxgg9208 4 หลายเดือนก่อน +1

    can we consider an octopus as an animal ? 😂

  • @labreynth
    @labreynth 2 หลายเดือนก่อน +1

    Would be better if you just showed completed classes in use then showed how they interacted, rather than empty scripts

  • @ensarija
    @ensarija 3 หลายเดือนก่อน +1

    Octopuses kicked out of animal world :D

  • @ebraheem_ahsen
    @ebraheem_ahsen 7 หลายเดือนก่อน +1

    thanks

  • @SSZaris
    @SSZaris ปีที่แล้ว +1

    🙏

  • @alfredogodoy6854
    @alfredogodoy6854 ปีที่แล้ว +1

    NOICE

  • @ScumlordStudio
    @ScumlordStudio 9 หลายเดือนก่อน +1

    How is an octupus not an animal os my question

    • @CodingQuests
      @CodingQuests  9 หลายเดือนก่อน +3

      its a fishy

    • @ScumlordStudio
      @ScumlordStudio 9 หลายเดือนก่อน

      @@CodingQuests valid point