Help with level save system

Discussion in 'Programming' started by Amith Haripersad, Feb 10, 2019.

  1. Amith Haripersad

    Amith Haripersad Member

    Joined:
    Sep 12, 2018
    Posts:
    7
    Hey Guys

    I managed to download a very old yet simple tutorial of making a level lock/unlock system.
    The problem is, how do i add a save system to it?
    A game will start will level 01 unlocked. Once this level is completed, level 02 gets unlocked. How do i save this progress so that when the player restarts the game, it does not lock all levels that the player completed already?
    If anyone could please have a look at the example and modify or assist with a solution, i would be really greatful
    This is the code...

    Code:
    
    CREATE EVENT
    if (score>50)
    {
        sprite_index=sprite_level_02;
        image_index=1;
        image_speed=0;
    }
    else
    sprite_index=sprite_level_02;
    image_index=0;
    image_speed=0;
    {
    }
    
    MOUSE LEFT PRESSED EVENT
    if (score>50)
    {
        transition_kind=0;
        room_goto(level_02);
    }
    else
    {
        show_message("get 50 points to unlock this level");
    }
     
  2. O.Stogden

    O.Stogden Member

    Joined:
    Jul 25, 2018
    Posts:
    181
    Best to use an ini for this kind of thing really.

    When your score first passes 50, put something like this in:

    Code:
    ini_open("progress.ini")
    ini_write_real('progress', 'level2', true)
    ini_close()
    
    Then when you wish to check, probably upon opening your level select.

    Code:
    ini_open("progress.ini")
    level2unlocked=ini_read_real('progress', 'level2', false)
    ini_close()
    
    Then do a check to see if level2unlocked is equal to true or false.
     
  3. kerim

    kerim Member

    Joined:
    Aug 10, 2018
    Posts:
    13
  4. Amith Haripersad

    Amith Haripersad Member

    Joined:
    Sep 12, 2018
    Posts:
    7
    Thank you but i cant seem to get it to work
    Would you mind updating my code in order for me to see where i am going wrong please? would appreciate that
     
  5. O.Stogden

    O.Stogden Member

    Joined:
    Jul 25, 2018
    Posts:
    181
    I would need to see what you're trying in order to help.

    Once you achieve score 50, or when you finish level one, put the first piece of my code in, that opens the ini file, and writes a line to it saying that level 2 is unlocked.

    Then, perhaps in a create event of a controller object in the level select room, have it run the second piece of code I put up, that reads from the ini file and sets "global.level2unlocked" to either false or true, depending on whether the level is unlocked or not. I've changed to a global variable here incase each level in the level select has a separate object you click on for starting the level

    Then you can make a check in the object that you click on to start level 2:

    Code:
    if global.level2unlocked=true
    {
    playable=true
    }
    else
    {
    playable=false
    }
    
    I can't get more specific than this without seeing your code.
     

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