Using Enums in GDScript for Better Code in Godot 4

Поделиться
HTML-код
  • Опубликовано: 28 дек 2024

Комментарии • 26

  • @furroy
    @furroy Год назад +26

    if you want to print an enum so you can read the name instead of seeing the number, print_debug(FireState.keys()[fire_state])

  • @yndajas
    @yndajas Год назад +9

    This is the first I've heard of upper snake case being called 'screaming snake case' - I love it!

  • @matheus5806
    @matheus5806 Год назад +11

    In case anyone is wondering, at 8:37 you have to reload the project to show the documentation

  • @ozbonus
    @ozbonus Год назад +4

    At 8:44 the doc string isn't being added to the inspector because there are outstanding syntax errors that have to be resolved first.

  • @Slipy61
    @Slipy61 2 месяца назад +2

    Bonus points for teaching me about Ctrl+D

  • @deethanyter7324
    @deethanyter7324 Год назад +9

    8:50 bro, you didn't edit it out. ☠😂
    Great video btw. Ive always been scared of dealing with anything inside a { } or [ ] but this video made it really simple. I appreciate it man

  • @charliecharliewhiskey9403
    @charliecharliewhiskey9403 2 месяца назад

    A good thing about doing it this way, is that you can expand the list - *backwards*. That is, imagine you have firetype double and triple, and only later decide to have a single-shot fire type too; you can put it in the enum list, *before* the double, and because everything is using the enum, it breaks nothing at all.
    You can also do things like have an enum and an array at the top of your file that are in parity, and use the enum as an index for the array, so that you can always just quick-access the correct array element from another class no matter whether you've changed things. I found that really useful when making some temporary debugging tools.

  • @HanyElsafty-sn9oc
    @HanyElsafty-sn9oc Месяц назад

    I finally understood enums thanks to you

  • @Seraph120
    @Seraph120 2 месяца назад

    Thank You for showing this. You mad it informative and easy to get

  • @KevinQuillen-m4o
    @KevinQuillen-m4o 19 дней назад

    Thank you! simple and to the point.

  • @entei6736
    @entei6736 Год назад +2

    Brett your tutorials are invaluable. Thank you for contributing to godot community

  • @unrealingenium-iz7ds
    @unrealingenium-iz7ds Год назад +2

    Very helpful as always. And wow you make a lot of videos fast!

    • @brettmakesgames
      @brettmakesgames  Год назад

      Thanks! I record them in batches then release them regularly, like a TV season. There may be gaps between seasons, but I've got lots of ideas and plans for future videos.

  • @PorChorrr
    @PorChorrr 10 месяцев назад

    This is a really well made tutorial! Thank you!!

  • @D.E.Nicolas.Goncalves
    @D.E.Nicolas.Goncalves Год назад

    this is a great advice! First we make it work, than we polish

  • @benjaminhill01
    @benjaminhill01 Год назад +2

    Why do your enums show the string name in the inspector but mine show int? For example your Fire Type enum shows as single. But when I try to replicate that I only see 0?

  • @yaseltamayo2367
    @yaseltamayo2367 Год назад

    It helped me a lot. Thank you!

  • @PokemanZ0N6
    @PokemanZ0N6 Год назад

    Thanks, this is exactly what I needed

  • @635574
    @635574 8 месяцев назад

    I was just making UI prototype that has a bunch of toggles and moves a few frames of some sprites with one button, this seems a lot better way to select from a list of things.

  • @nvanderhoff
    @nvanderhoff 9 месяцев назад

    the fainting is actually funny because it gives emotion to the mistake.type

  • @05anonymous50
    @05anonymous50 6 дней назад

    I’m a beginner so forgive me but can someone explain why the index of an enum value would ever be needed if enum values are constant and hard coded? When would I ever not reference it by name?
    Also follow up question: wouldn’t directly setting the integer value (do you even call it the index?) functionally turn your enum into a dictionary of constants?
    Edit: kind of realizing the nature of my question is really just what use the integer values have? This video is immensely helpful but it only contains an example of using enums as mini state machines and I can’t help but feel there’s more to them, possibly?

  • @vizionthing
    @vizionthing 4 месяца назад

    I found enum a few days back, using it for game state, really needed to know how to access it globally across scenes - thanks. I now know class_name :)

  • @Xiaoxiao738
    @Xiaoxiao738 Год назад

    When you access fire input though in the bullet your just accessing the enum which is a const so that wont change. You need to access the export variable that you made to actually check some logic. But how do I access a export variable from another script?

  • @dr_pennysworth
    @dr_pennysworth Год назад +1

    I'm glad to see people teaching others but it is sad to see such poor programming practices being taught. Having an enum with each amount of times fired is just poor use of an enum. Your better off using the enum to choose if its single fire, burst, or full auto and if its on burst have an int saying how many time to fire instead of having if statements and an enum for each amount of bullets to be fired. Also making multiple vars for each bullet is kind of a waste when you could just put all that repeated code into a for loop for the bullets and only have to write that stuff once.