Why EVERY Gamemaker dev should use Structs

Поділитися
Вставка
  • Опубліковано 19 гру 2024

КОМЕНТАРІ • 38

  • @faxinspace
    @faxinspace 7 місяців тому +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.

  • @ScubaAries
    @ScubaAries 5 місяців тому

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

  • @ShaolinMonkster
    @ShaolinMonkster 9 місяців тому

    More of these please!!! Subbed

  • @pemba999
    @pemba999 11 місяців тому

    love your videos, hope you come back soon!

  • @SimianVirus
    @SimianVirus 11 місяців тому +1

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

  • @PixelKnight93
    @PixelKnight93 11 місяців тому

    Thank-you for this!

  • @DR-T-ij9mc
    @DR-T-ij9mc 8 місяців тому

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

  • @SARclips_Official
    @SARclips_Official Рік тому

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

  • @salvadorgonzales1
    @salvadorgonzales1 9 місяців тому +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 9 місяців тому

      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 9 місяців тому

      @@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 9 місяців тому

      ​@@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_  9 місяців тому

      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

  • @artorias-24
    @artorias-24 10 місяців тому

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

    • @GoldScale57
      @GoldScale57 10 місяців тому +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 10 місяців тому

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

  • @akalex770
    @akalex770 Рік тому +1

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

  • @ps4ljaska683
    @ps4ljaska683 Рік тому

    hard

  • @georgehennen
    @georgehennen 3 місяці тому

    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_  2 місяці тому

      @@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 25 днів тому

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

    • @georgehennen
      @georgehennen 25 днів тому

      @@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 24 дні тому

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

    • @RiptideDev_
      @RiptideDev_  24 дні тому

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

  • @smokinjoe9415
    @smokinjoe9415 7 місяців тому +1

    Why does the text look so terrible?

    • @RiptideDev_
      @RiptideDev_  7 місяців тому +3

      I used the worst font imaginable.

  • @jeremiah8468
    @jeremiah8468 Рік тому +1

    Hello

  • @Zeldoriis
    @Zeldoriis 9 місяців тому

    sword = mew
    hehe

  • @Neodx2
    @Neodx2 7 місяців тому +3

    sword= mew item 🗿🗿

  • @Oltronoobpro
    @Oltronoobpro Рік тому

    What's your discord server?