5 Tricks For Better GDScript in Godot

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ม.ค. 2025

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

  • @stayathomedev
    @stayathomedev  7 หลายเดือนก่อน +3

    Do you have your own tips when working with GDScript?
    🔥 SUPPORT THE CHANNEL ►► www.patreon.com/StayAtHomeDev_

  • @julietmikealpha
    @julietmikealpha 7 หลายเดือนก่อน +30

    Use a linter - GDFormat is my preferred choice; it will format the document following the official style guide, including line-breaks

    • @themghicks
      @themghicks 7 หลายเดือนก่อน

      I just discovered gdtoolkit a few days ago and I'm loving it!

    • @Art-n-Chill
      @Art-n-Chill 7 หลายเดือนก่อน

      I was wondering if Godot had a linter of some sort but never looked into because I’m usually pretty diligent in good formatting. This is good to know, thank you

    • @truc_e
      @truc_e 7 หลายเดือนก่อน

      this is the real tip lol, I feel like "cleaner code" shouldn't just mean formatting

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

      How do I do that in Godot 4.3? is it the plugin gdLinter? they warn about when you save you might lose your code for it runs python script on the file an you might lose data

  • @smiffsoft
    @smiffsoft 7 หลายเดือนก่อน +9

    Good tips for any language, but the last one specifically for GDScript made this really useful for me, I didn't realise you could do that

  • @PawelKozlowski77
    @PawelKozlowski77 7 หลายเดือนก่อน +9

    0:46 is new for me but soo intuitive. I always struggled to differentiate between "temporary comment", and "comment that is here to stay"

  • @MauriMahtava
    @MauriMahtava 5 หลายเดือนก่อน +1

    A tip from history from old C coder. Do not use any numeric values in the code, except 0 for initialization. When you use numeric values, then after you read the code, you don't know background of the value. It is self documentary to use constants all the time. When you need to edit your code, you just need to change the constant.
    This is the number one code cleaning tip when going professional.

  • @imogen__
    @imogen__ 7 หลายเดือนก่อน +22

    You can also have your expression continue over multiple lines by writing a backslash \
    at the end of the line. This doesn't look as clean as the brackets mentioned in the video though.

  • @pipeliner8969
    @pipeliner8969 7 หลายเดือนก่อน

    your channel is becoming more a more a huge goldmine. Heavily underrated!

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

    for the last tip, you can use "\" for multiple lines

  • @Atropos148
    @Atropos148 7 หลายเดือนก่อน

    Thank you so much for talking about documentation comments :) i always wanted something like that in Godot, now i don´t have to keep going back to my own functions to remember how they work, i can just write documentation

  • @Rai2M
    @Rai2M 7 หลายเดือนก่อน

    Basically, this is the video about code style )
    Simple but never gets old )

  • @asdfasdfasdfasdf-f3p
    @asdfasdfasdfasdf-f3p 3 หลายเดือนก่อน

    Well, writing clear code is much, much more than just five tips. In this video, you don't even scratch the surface. You blew five tiny specks of dust from it.

  • @BigBossRazz
    @BigBossRazz 7 หลายเดือนก่อน +3

    Great tips! That last one was new for me!

  • @computersciencestudentriverbat
    @computersciencestudentriverbat 7 หลายเดือนก่อน

    I'm a big fan of using Word Wrap for long lines. It's simple and works well when I resize the window for whatever reason.

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

      Word wrapping isn't your friend, because you often need to use different lines for semantic reasons and readability.
      a quick example
      this:
      var dot := Vector2(offset.x + radius * cos(alpha + angle_offset), offset.y + radius * sin(alpha + angle_offset))
      would look much better:
      var dot := Vector2(offset.x + radius * cos(alpha + angle_offset),
      offset.y + radius * sin(alpha + angle_offset))
      Imagine the expression is much longer than that. Word wrapping can completely f it up:
      var dot := Vector2(offset.x + radius * cos(alpha
      + angle_offset),
      offset.y + radius * sin(alpha
      + angle_offset))

    • @computersciencestudentriverbat
      @computersciencestudentriverbat 7 หลายเดือนก่อน

      @@Rai2M - I just put both examples that in my editor, it seems fine.

    • @Rai2M
      @Rai2M 7 หลายเดือนก่อน

      @@computersciencestudentriverbat Whatever works for you, buddy.

  • @tomppeli7727
    @tomppeli7727 7 หลายเดือนก่อน

    Good tips, I Iearned something new!

  • @goldkat94
    @goldkat94 7 หลายเดือนก่อน

    1:00 how can you write the hashtags before the marked text?

  • @MattEatsMochi
    @MattEatsMochi 7 หลายเดือนก่อน

    Is there a place I can learn more about 4? I struggle with naming stuff all the time and would love to see a full writeup.

  • @jayroi1814
    @jayroi1814 7 หลายเดือนก่อน

    Very nice, some of these suggestions are good for any developer, game or otherwise.
    I'm a professional software engineer and my company uses lint to enforce some of these things for our frontend (built in React).
    With this your git pipeline will actually fail if you have any lint warnings regarding styling like this that weren't automatically formatted by our pre-commit hooks.
    Very helpful.

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

    there should be something similar to prettier in VSCode within Godot which adds a default code style.

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

    Uhh.. why does keeping a trailing comma help to add items?

    • @ghostradiodelete
      @ghostradiodelete 7 หลายเดือนก่อน

      It doesn't. I was also baffled by this.

  • @AndrewGrofff
    @AndrewGrofff 7 หลายเดือนก่อน +6

    Most of these are things that should be handled by an auto formatter IMO. It would be awesome if Godot adds one but for now there is gdscript toolkit for linting and formatting

  • @ThiVasss
    @ThiVasss 7 หลายเดือนก่อน

    Any tips for grouping and naming for the filesystem?
    Like do you seperate scenes from scripts or do you save similar things (like an enemy scene and enemy scripts) in the same place for easier access?

    • @charliegnu
      @charliegnu 7 หลายเดือนก่อน

      I like keeping scripts together with their scenes and group scenes with folders. I've seen people just put all their scenes in one folder and scripts in another and that looks so messy to me.

    • @ThiVasss
      @ThiVasss 7 หลายเดือนก่อน

      @@charliegnu Yeah right now I do the same but I am always looking for the more efficient way. I wish the scenes with scripts were bundled together in the filesystem. (like next to each other)
      I also go between name sorting so the scripts that have the same name as the scenes are together but also tried by type which separates the scenes and scripts in 2 but keeps them in the same folder.

  • @charliegnu
    @charliegnu 7 หลายเดือนก่อน +2

    I wish godot had an opinionated autoformatter like many other modern languages have out of the box. Spend less time formatting and more time coding.

  • @TheRealKaiProton
    @TheRealKaiProton 7 หลายเดือนก่อน

    I do number 2 because it looks nicer in the code, I had no idea it was a coding rule

  • @lyghtkruz
    @lyghtkruz 7 หลายเดือนก่อน

    The comma at the end of elements for an array, dictionary is great for git repos. If you add an item to the array it's a single line change not 2 changes (1 for the comma and another for the new item). Great tips!

  • @laughingvampire7555
    @laughingvampire7555 5 หลายเดือนก่อน

    every time he says godot I listen "el gato"

  • @ulrich-tonmoy
    @ulrich-tonmoy 7 หลายเดือนก่อน

    godot editor editor need a little some code editor feature that all editor comes with nowadays like format on save

  • @jRsqILVOY
    @jRsqILVOY 7 หลายเดือนก่อน

    I wish the GDScript lang server would add a linter to do this like rustfmt in Rust.

  • @randomnyyStrannik
    @randomnyyStrannik 7 หลายเดือนก่อน

    Thank you

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

    instead of doing
    if condition_A && condition_B && condition_C:
    i like to do one of these
    if condition_A:
    if !condition_B: return
    if !condition_C: return

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

    Actually it's called SCREAMING_SNAKE_CASE

  • @gryzman
    @gryzman 7 หลายเดือนก่อน

    write more code to have better lighting ;)

  • @dingdong1112
    @dingdong1112 7 หลายเดือนก่อน

    hi sir i'm a new sub here hope you don't mind if i have a request
    i have a problem running my godot engine in forward and mobile renderer every time i try to run it, it just show black editor and i couldn't do any thing i hope you will see this and accept my request in return i will continue supporting your channel till the end of my life

  • @morganp7238
    @morganp7238 7 หลายเดือนก่อน

    The thing is that Godot is a game engine. To try to be an IDE too is a lot of work that is never going to come close to VSCode or Visual Studio.
    Just saying.

  • @theTeslaFalcon
    @theTeslaFalcon 7 หลายเดือนก่อน

    So u declare that "document comments" exist, but u never explained the difference between the 3 different comments u refer to.
    Comment where it's confusing.
    Use proper variable names so it's less confusing.
    Comments should be minimal.

  • @scotmcpherson
    @scotmcpherson 7 หลายเดือนก่อน +3

    Some expressions won’t work with a trailing comma. Most will, but not all. Just be warned.