JSON SAVING in GameMaker with STRUCTS

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

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

  • @GameMakerStation
    @GameMakerStation  4 года назад +15

    You can also encrypt and compress buffers, that's why they're so great for saving data!
    Let me know what you thought of this video, and if you have video suggestions/requests, do comment!

    • @misterr3083
      @misterr3083 4 года назад +2

      Excellent as always!! I love how clear and structured your videos are, no waffle/fluff, straight to the good stuff, amazing! Thank you so much Matharoo.

    • @Quentin94
      @Quentin94 2 года назад +1

      I got the saving/loading down. Is there a tutorial or a guide showing how to encrypt buffers anywhere?

  • @dobysrule9988
    @dobysrule9988 3 года назад +3

    I rarely leave comments on youtube but I have to give credit where credit is due. For someone like me who has development background but new to GM2 simple googling for answers usually brings a lot of stuff that is based on older techniques, which may lead you to a rabbit hole. I like JSON but I was under the impression that the only way to save/load data in GM was by using maps and grids and I was very relieved to find this video. I have found that whenever i had a question and googled for answers for GM2, your tutorials were often the ones I ended up watching. People often forget that technology changes rapidly so often times a tutorial from 4-5 years ago might well be obsolete now. Thanks!

  • @NoahNCopeland
    @NoahNCopeland 4 года назад +8

    Thank you actually explaining what JSON is, instead of just assuming we know.
    I'm so freakin' tired of Game Maker videos talking to me like I got a degree in computer science a few years back.
    I use Game Maker for a reason! I wanna spend more time being creative and less time thinking about numbers.
    Thank you.

    • @GameMakerStation
      @GameMakerStation  4 года назад +3

      That is the reason why I was so late to the JSON party. Everyone kept saying "use JSON, you should; hMmm" but no one explained what it was or why it was so good. So while making this video I felt that there were others who had probably heard of JSON but did not know what it meant, so the explanation was necessary.
      Thanks for your support 😊

  • @isaacsanchez3839
    @isaacsanchez3839 3 года назад

    This is the best basic save and load tutorial, you explain things in a brief clear way which makes it much easier to understand

  • @kingofowlsdev
    @kingofowlsdev 4 года назад +11

    Shaun Spalding: *making json saving tutorial*
    Matharoo after two hours: *also making json saving tutorial*
    *Meme about a guy who follows a girl, but he is stopped by another guy*

  • @AiguretDuren
    @AiguretDuren 4 года назад +1

    Thanks, Matharoo. Great video! I'm glad I'm getting into GMS 2 when all of these great updates are coming out.

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

    Hi there, isn't JSON editable ? Players will be able to "cheat" modfying the json data right ?

  • @electrosaber0429
    @electrosaber0429 4 года назад +3

    This is amazing, good job!

  • @CreaturesOrigins
    @CreaturesOrigins 3 года назад +1

    How would one handle the case of writing ds_lists and ds_maps that are nested within a struct to json? Must they be converted to arrays?

    • @GameMakerStation
      @GameMakerStation  3 года назад +2

      If you just save the struct as it is at runtime, then only the DS IDs will be saved but the data inside them will not be serialized at all. You don't have to convert the maps and lists to structs and arrays though - use ds_map_write and ds_list_write to serialize the data as a string and save that into the struct/array before converting to JSON. Use ds_map_read and ds_list_read to convert them back to DS after loading.
      manual.yoyogames.com/GameMaker_Language/GML_Reference/Data_Structures/DS_Maps/ds_map_write.htm
      manual.yoyogames.com/GameMaker_Language/GML_Reference/Data_Structures/DS_Lists/ds_list_write.htm

    • @CreaturesOrigins
      @CreaturesOrigins 3 года назад

      @@GameMakerStation Elegant solution. Thank you for the detailed reply!

  • @walney2008
    @walney2008 2 года назад

    hello, I would like to learn how to do to have a fisherman on the boat, have the sea with the fish below going side to side appearing random, and with this fisherman with the arrows I can increase and decrease the fishing rod line and catch the fish with hook and pull the boat, can you explain?

  • @Kezarus
    @Kezarus 4 года назад

    Math, you helped me a LOT with this tutorial, mate! Big thanks to you! =D

  • @leoriley7684
    @leoriley7684 2 года назад

    is there any way to save and load on game end and game start?

  • @patriciaduffy2479
    @patriciaduffy2479 3 года назад

    Nice video! How would this be implemented when changing rooms? For example, if I have opened chests and enemies in prior room, how would that data be saved?

    • @GameMakerStation
      @GameMakerStation  3 года назад

      See this: www.yoyogames.com/en/blog/multiple-levels-tutorial

    • @patriciaduffy2479
      @patriciaduffy2479 3 года назад

      @@GameMakerStation Thanks for responding! I actually saw this before. What I don't understand is how to save specific object variables and numbers, data, etc that can be loaded once the game is quit. This link looks like just room persistence using code but I don't understand how this would be saved to a file and then loaded after the person quits the game.

    • @patriciaduffy2479
      @patriciaduffy2479 3 года назад

      Meaning across many rooms; not just the current one.

  • @igniz-2591
    @igniz-2591 4 года назад +1

    Thx bro this vid rly helped
    Btw first and uhh the concept of JSON is actually rly ez

    • @GameMakerStation
      @GameMakerStation  4 года назад +1

      It is! JSON is one of those things that's easy to understand but sadly isn't as widely used as it should be, within the beginner community. These new functions for Structs are really going to help, and make it easier for beginners to use the power of JSON!

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

    What type of file does this save it as? Is it a txt file?

  • @prowokator
    @prowokator 4 года назад +3

    If you are really 21, congrats! When I was that age all I knew was how to down a 12 pack of beer and still get into a bar. And how to do donuts with a diesel forklift.

  • @Perzess
    @Perzess 3 года назад

    Is it possible to save global variables?

  • @siba2893
    @siba2893 4 года назад

    Hey Matharoo, is your udemy course up to date with the new stuff in GM 2.3? I'm thinking in buying it.

    • @GameMakerStation
      @GameMakerStation  4 года назад

      I have added updates to cover any changes that can cause confusion in students, though I have not implemented new features (such as structs, Sequences, etc.) because the course is essentially based on v2.2, and I'm working on a new course for v2.3+. That said, the course is still relevant if you want to make a crafting game, and a lot of people are getting and learning from the course even after the v2.3 update. I am also always available for support, should you face any issues.
      If you decide to get it, please use my referral link as Udemy takes a smaller cut from these purchases: www.udemy.com/course/crafting/?referralCode=81153850CB978F6D9ECC
      Thanks!

  • @maxmi3091
    @maxmi3091 3 года назад

    how would you implement this system in a game with more then one room?

    • @GameMakerStation
      @GameMakerStation  3 года назад +1

      Just to make rooms "persistent", I'd store the saved data for each room's instances in a global struct. Look out for my next tech blog on the YoYo Games site, it will have an answer to your question.

  • @willm127
    @willm127 4 года назад

    Finally! Proper JSON support! 😭 Great video!

  • @CopyCopyOriginal
    @CopyCopyOriginal 3 года назад

    stringify doesn't handle methods! my methods attached to my structs are lost in this process and it really ruins my strategy. could you mention a workaround for this?

    • @GameMakerStation
      @GameMakerStation  3 года назад +1

      When you save the struct, save the name of the struct's constructor (think you can get that by running instanceof() on it) and when you load the struct, find the constructor using asset_get_index() and then new() it. You can then apply data from your loaded struct into that new struct and that way you will get a struct with your loaded data and all relevant methods.

    • @CopyCopyOriginal
      @CopyCopyOriginal 3 года назад

      @@GameMakerStation thank you so much for the quick reply and the nice strategy! so far I have it working where I can create a new struct, but I'm struggling a bit to take the methods from the new struct and attach them to the old. (hour later) I think I just got it

  • @erik_arman
    @erik_arman 3 года назад

    Informative video with great editing, but is it possible to save global variables? All the tutorials I've seen on JSON structs and arrays in GameMaker only save local variables. I tried saving global variables but it doesn't seem to be working. Do you have any tips on how to save global variables?

    • @GameMakerStation
      @GameMakerStation  3 года назад

      Sure, you can do that. Variables are simply references to values anyway, so how you get them shouldn't be an issue. What's the problem here?

    • @erik_arman
      @erik_arman 3 года назад

      ​@@GameMakerStation
      Well, I tried to make an array to save my players health and position with this code:
      var _saveData = array_create(0);
      with (obj_player)
      {
      var _saveEntity =
      {
      obj : object_get_name(object_index),
      y : y,
      x : x,
      health : global.hero_health,
      }
      array_push(_saveData, _saveEntity);
      }
      var _string = json_stringify(_saveData);
      var _buffer = buffer_create(string_byte_length(_string) +1, buffer_fixed, 1);
      buffer_write( _buffer, buffer_string, _string);
      buffer_save ( _buffer, "savedgame.save");
      buffer_delete( _buffer);
      show_debug_message("Game saved! " + _string);
      But it didn't seem to work. It saves the player's position, but not the health. I think I'm doing something wrong in the syntax but I'm so new to JSON that I have no idea what.

  • @philosopherhobbs
    @philosopherhobbs 4 года назад

    Ok, so what do I do with all the other data structures? Stop using them? Convert every single one into a struct or array? I should just be able to tell something all the data I want to save and it happens (whether built into GMS or something custom). There's just a lot of questions left open here.

    • @GameMakerStation
      @GameMakerStation  4 года назад

      No need to stop using other data structures if you're already using them in your systems. It's just about knowing what works best for what you are doing.

  • @speeddman100
    @speeddman100 3 года назад

    It would have been helpful if you let us know how to save lists/maps etc at the end of the video, instead of telling us this method won't work for it, so we are screwed.

    • @GameMakerStation
      @GameMakerStation  3 года назад

      The whole point of this video was that structs and arrays could now be saved as JSON and you wouldn't have to use lists and maps anymore. For them please use json_encode() and json_decode(), they do the same thing as stringify and parse but are made for maps and lists.

  • @karlstenator
    @karlstenator 4 года назад

    Still in beta >_

  • @ignaciosb8779
    @ignaciosb8779 4 года назад +1

    Good tutorial. I'll be waiting for 2.3.1.
    I also got to know some functions I didn't know yet like ```find_instance``` .