Why EVERY Gamemaker dev should use Structs

Поделиться
HTML-код
  • Опубликовано: 9 фев 2025
  • Very few gamemaker users I've seen actually use structs, when they are in fact one the best ways to encapsulate and organize data. Please use them more, they're awesome!
    Support my game development on Patreon for cool stuff! Currently trying to fund an animated trailer for my game Earthward!
    www.patreon.co...
    Join our Discord: / discord

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

  • @faxinspace
    @faxinspace 9 месяцев назад +7

    this video explained constructors in a way the documentation couldnt
    idk if thats because its 2 am or what
    but it makes sense now, and now i want to rewrite my struct-based-systems because they are all hard coded, and im currently using a switch statement to cycle between them
    This is the information ive been needing for my quest system
    thank you

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

    It's very nice of you to offer different helpful solutions all the time.

  • @winfid
    @winfid 7 месяцев назад

    I really enjoy your Terraria Modding series, and videos like these top it all off amazingly

  • @ShaolinMonkster
    @ShaolinMonkster 11 месяцев назад

    More of these please!!! Subbed

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

    Thank-you for this!

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

    Finally! Tell me why! (Oh no, now that song is stuck in my head.)

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

    love your videos, hope you come back soon!

  • @DR-T-ij9mc
    @DR-T-ij9mc 9 месяцев назад

    Could you provide a download for the code in this video? Would love to look into your code for the text boxes

  • @salvadorgonzales1
    @salvadorgonzales1 11 месяцев назад +1

    I find the 'new' operator to be confusing and are specialized for the constructor only.
    "It is important to note that calling new on any function that has not been flagged as a constructor will cause a runtime exception"
    -GMS Manual

    • @MaviLeb
      @MaviLeb 11 месяцев назад

      It's constructing a new structure in memory for you. A normal function usually doesn't do that but just returns the result of that function.
      So, it's basically easier for you (and the compiler) to distinguish the two when reading the code.
      Otherwise,
      a = f()
      could be either one, which would be more confusing.
      The compiler enforcing that is a great help, because you can't create an ambiguous situation, which could lead to longer debugging sessions and head aches.
      So, in the end, it helps you.

    • @salvadorgonzales1
      @salvadorgonzales1 11 месяцев назад

      @@MaviLeb Thanks for the answer, does this impact performance though? making new structure in memory just for a specific instance every time that instance exists or something

    • @MaviLeb
      @MaviLeb 11 месяцев назад

      ​@@salvadorgonzales1 That can't be answered with a general statement, because it depends a lot on how many times you actually create instances.
      Usually, that should be very fast and not be a problem in most cases. But if you create thousands of instances every single frame of your game, it can get a significant performance issue. Some rule of thumb is that things that only happen when the player presses some button don't matter and things that are processed each frame can be a problem but don't need to be.
      However, in this case, I'd advice to not think too much about this problem when creating your game. If it makes your code more simple to understand and maintain, that should have a higher priority. The reason is that this problem can be solved by pooling your instances. Meaning, you create some pool of instances which you then re-use whenever you need them. In most cases, this can be implementend without changing your code structure too much after the problem actually shows up.
      For example for a bullet-hell game like Vampire Survivors you could know that you have some maximum number of any enemy type at any one time in your level, for example 200 bats. So, you could just make a pool (this could be an array for example) of 200 bats which you then re-use every time a bat should be spawned. For this you just change their values every frame. Like, when a bat is killed by the player it is set to be invisible (or not rendered), not destroyed. And when you want to spawn a new one, you get an invisible one from the pool, set their variables back to normal and show it. You can do that for any instance of structures - or any data you have for that matter.
      There's a free book online called gameprogramming patterns. It has a section about 'object pooling', you can check that out to get a better explanation of the pattern.

    • @RiptideDev_
      @RiptideDev_  11 месяцев назад

      New allocates memory for an object. This is how it is done in C++ and C#, and many other languages. Gamemaker is abstracted to the point where it manages memory for you mostly, except for structs

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

    Is it possible you could redo some of the earlier videos in the tutorial series

  • @artorias-24
    @artorias-24 Год назад

    is there any downside to using a lot of structs >=?

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

      Creating structs is slower than creating arrays but not by too much. So probably don't create them for temporary things every frame.
      I wouldn't worry too much about using them in general though. They're very helpful and I'm using quite a few of them in my project.

    • @artorias-24
      @artorias-24 Год назад

      @@GoldScale57 Thanks for the response. I am currently working on a simple RPG game and i have few structs set up that make inventory management a breeze! Also being able to track all player variables inside a single player struct helps a lot.

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

    What games have you made though?
    Every single person I talk to tells me to do this, or that and they have never made a game. Not even a gamejolt published game.
    I have published several steam games and never use any of this.

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

      @@georgehennen Hey! So my solo title on steam is called Bitlands, and I’ve composed music for another steam game called Koko: Last Leaf, and Paradigm on itch. My current project Earthward is on steam for select users while in alpha. I’ve also been a programmer and artist for several game jams which you can find on my itch (lots of them can be played via browser, so give it a shot!) my favorites are Lilypad Lowdown and Daisy’s Quest, but there are others as well.
      (Bitlands was my first ever published game, I made it in highschool)

    • @Nicholas-nu9jx
      @Nicholas-nu9jx 2 месяца назад

      Structs are overrated and lead to cache misses that hurt game performance

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

      @@Nicholas-nu9jx Really? Please elaborate or even put a video up on your channel. People keep telling me to use structs so I learned them, now you are telling me this.

    • @Nicholas-nu9jx
      @Nicholas-nu9jx 2 месяца назад

      @georgehennen I'll see if I can make a video in gml or find third party sources

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

      @@Nicholas-nu9jx This is essentially saying the concept of classes in programming leads to inefficient code. This is not the case at all. Structs are simply allocated blocks of memory that contain data, actually making them more efficient than objects due to the fact they aren’t managed or put in a render/partition list, not to mention do not have all the properties of an object. If structs in Gamemaker are giving you performance issues, then it sounds like you need to manage your structs better and destroy them when they’re not needed

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

    hard

  • @smokinjoe9415
    @smokinjoe9415 9 месяцев назад +1

    Why does the text look so terrible?

    • @RiptideDev_
      @RiptideDev_  9 месяцев назад +3

      I used the worst font imaginable.

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

    I use the constructor structs for 99% of the game content i create.

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

    Hello

  • @Zeldoriis
    @Zeldoriis 11 месяцев назад

    sword = mew
    hehe

  • @Neodx2
    @Neodx2 8 месяцев назад +3

    sword= mew item 🗿🗿

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

    Your upload schedule could be better

    • @RiptideDev_
      @RiptideDev_  Год назад +5

      I never had a schedule to begin with

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

    What's your discord server?