GM:S 1.4 Inventory issue [SOLVED]

Discussion in 'Programming' started by StynlFear, Jul 15, 2018.

  1. StynlFear

    StynlFear Member

    Joined:
    Jun 28, 2018
    Posts:
    19
    I have made an inventory and i made a saving system.
    But for some reason It doesnt want to save the variables.
    here is the code for saving
    Code:
    if(file_exists("Save.sav")){
        file_delete("Save.sav");
    }
    ini_open("Save.sav");
    var SavedRoom = obj_input.previous_room;
    ini_write_real("Room","room",SavedRoom);
    ini_write_real("Inventory","item",obj_inventory_box.item);
    ini_write_real("Stats","hp",obj_player_Stats.hp);
    ini_write_real("Stats","maxhp",obj_player_Stats.maxhp);
    ini_write_real("Stats","stamina",obj_player_Stats.stamina);
    ini_write_real("Stats","maxstamina",obj_player_Stats.maxstamina);
    ini_write_real("Stats","expr",obj_player_Stats.expr);
    ini_write_real("Stats","maxexpr",obj_player_Stats.maxexpr);
    ini_write_real("Stats","level",obj_player_Stats.level);
    ini_write_real("Stats","attack",obj_player_Stats.attack);
    ini_write_real("Stats","armor",obj_player_Stats.armor);
    ini_write_real("Stats","gold",obj_player_Stats.gold);
    ini_write_real("Stats","maxmana",obj_player_Stats.maxmana);
    ini_write_real("Stats","mana",obj_player_Stats.mana);
    ini_write_real("Items","health_potions",obj_player_Stats.health_potions);
    ini_write_real("Weapon","weapon_sprite",obj_player.weapon_sprite);
    ini_write_real("Skill","invisible",obj_player_Stats.invisible);
    ini_write_real("Position","x",obj_player.x);
    ini_write_real("Position","y",obj_player.y);
    ini_close();
    show_message("Game Saved");
    And this is for loading
    Code:
    if(file_exists("Save.sav")){
        ini_open("Save.sav");
        var LoadedRoom = ini_read_real("Room","room",rm_one);
           obj_inventory_box.item = ini_read_real("Inventory","item",obj_inventory_box.item);
        obj_player_Stats.hp = ini_read_real("Stats","hp",5);
        obj_player_Stats.maxhp = ini_read_real("Stats","maxhp",5);
        obj_player_Stats.stamina = ini_read_real("Stats","stamina",10);
        obj_player_Stats.maxstamina = ini_read_real("Stats","maxstamina",10);
        obj_player_Stats.expr = ini_read_real("Stats","expr",0);
        obj_player_Stats.maxexpr = ini_read_real("Stats","maxexpr",3);
        obj_player_Stats.level = ini_read_real("Stats","level",1);
        obj_player_Stats.attack =ini_read_real("Stats","attack",1);
        obj_player_Stats.armor = ini_read_real("Stats","armor",0);
        obj_player_Stats.gold = ini_read_real("Stats","gold",obj_player_Stats.gold);
        obj_player_Stats.mana = ini_read_real("Stats","mana",obj_player_Stats.mana);
        obj_player_Stats.maxmana = ini_read_real("Stats","maxmana",obj_player_Stats.maxmana);
        obj_player_Stats.invisible = ini_read_real("Skill","invisible",obj_player_Stats.invisible);
        obj_player_Stats.health_potions = ini_read_real("Items","gold",obj_player_Stats.health_potions);
        var xpos = ini_read_real("Position","x",64);
        var ypos =ini_read_real("Position","y",32);
        if(!instance_exists(obj_player)){
            instance_create(xpos,ypos,obj_player);
        }
         obj_player.x = xpos;
        obj_player.y = ypos;
        obj_player.weapon_sprite = ini_read_real("Weapon","weapon_sprite", obj_player.weapon_sprite);
        ini_close();
        room_goto(LoadedRoom);
    } else
    {
    show_message("Saves not found");
    }
    In the inventory box i have an variable item that's tracking the items in the slots.
     
  2. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    315
    Is that show_debug_message displayed("Game saved!")? Are you getting errors? Did you check the working_directory to see if the INI is created? If it is, does it store anything in it?

    More info is needed here.
     
  3. Fabseven

    Fabseven Member

    Joined:
    Oct 7, 2016
    Posts:
    350
    Got myself strange things while use ini files, but in the end to make sure i am working on the good file i use working_directory as Paskaler said and i first write something in my file then use the windows explorater to find it , modify it with new values and then try to read it and cheking values.
    I think the rep used in test mode and in real mode (after the game is installated) are not the same ...
     
  4. StynlFear

    StynlFear Member

    Joined:
    Jun 28, 2018
    Posts:
    19
    Sry.I'm a dumbass.I tried to store multiple variables from different objects in that .Its solved
     

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