1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Saving based on the room the player is in with Drag and Drop

Discussion in 'Programming' started by GamingDragomachina, Jun 29, 2019.

  1. GamingDragomachina

    GamingDragomachina Member

    Joined:
    Jan 2, 2019
    Posts:
    15
    So, i've been working on making a platforming game using Drag and Drop in Gamemaker 2 Studio. I'm struggling with a save system. The sort of system i want is if the player is in a certain room, the game saves automatically. For example, once the player gets to a new world, saving it so that when they load the game, they can go right back to that world's level select screen.

    Any help you can offer is appreciated. ^-^
     
  2. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    423
    You should make something generic that takes the player to new worlds so you can reuse it. When you trigger it it should check if the save file exists. If it doesn't it makes one. If it does it edits it. All you need to write to it is the world or room name. Then make a new starting room and load it first when you run the game. In the room's creation event it should also check if the file exists and if it does open and read the the world name then go to that worlds level select screen.

    The ini file stuff should be all you need. This is their format:
    Code:
    [Section]
    Key = Value
    All you need to store and read is something like this:
    Code:
    [Player]
    World = rmWorldOneLevelSelect
     
  3. GamingDragomachina

    GamingDragomachina Member

    Joined:
    Jan 2, 2019
    Posts:
    15
    Alright, just one quick question, For where you put player, do i use my player object for that slot?
     
  4. Bayesian

    Bayesian Member

    Joined:
    Sep 13, 2016
    Posts:
    423
    I'm not quite sure what you mean. Where do you want to put the player and when? And what slots?
     
  5. GamingDragomachina

    GamingDragomachina Member

    Joined:
    Jan 2, 2019
    Posts:
    15
    When you put player, did you mean i put my player object there? Or what did you mean? and what i want to do is just save the player so they can load in on the level select screen of the world their currently on, and save their progress.
     
  6. pipebkOT

    pipebkOT Member

    Joined:
    Dec 13, 2018
    Posts:
    212
    https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/file handling/ini files/index.html

    go read the manual, ini files are the solution for you, you need to save the room where the player is gonna be loaded. the x and y position, etc

    you need to create a save object, in it you put the code about saving(in the create event)

    you need to use ini_open and ini_write_real or ini_write_string

    example save code:
    Code:
    ini_open("savedata.ini");
    ini_write_real("Player,"currentworld", room)
    ini_write_real("Player","coins","global.coins")
    ini_write_string("Player", "name", global.Name);
    ini_close();
    you create the save instance when the player is trown back to the world level select.




    you create a load game object that loads you in the last room saved

    example load code
    Code:
    ini_open("savedata.ini");
    global.world=ini_read_real("Player,"currentworld", 0)
    global.coins=ini_read_real("Player","coins","0")
    global.name=ini_read_string("Player", "name", "");
    ini_close();
     
  7. GamingDragomachina

    GamingDragomachina Member

    Joined:
    Jan 2, 2019
    Posts:
    15
    Alright, My only question is what do i insert for the target field? If you want an image example, here it is. what do i put as the target? upload_2019-6-30_2-46-59.png
     
  8. GamingDragomachina

    GamingDragomachina Member

    Joined:
    Jan 2, 2019
    Posts:
    15
    Also, Do i have to repeat the same process for each individual level select room? Like do i have to make new objects for each world save, or do i just do the same code under the same save object?
     
  9. pipebkOT

    pipebkOT Member

    Joined:
    Dec 13, 2018
    Posts:
    212
    @GamingDragomachina

    Use gml, try to learn how to use it . Not drag n drop .
    Gml Is more easier and less tedious.
    Also the majority of people on this forum use gml
    And game maker can port all the drag and drop code that you have made until now into gml so you don't have to worry about it

    So take my advice and switch to gml . It will benefit you . But of course. Its your decision


    About the object
    You only need one save object that saves everything .so all the save code has go be inside the same object.

    Then you can call the save object from any room and in any moment when you want to save.
    With the function instance_create_layer





    About the image. Since I don't use drag n drop am just guessing that in the target you need to put the variable that you want to assign the saved variable . In this case it should be global.world
     
    Last edited: Jul 1, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice