GameMaker (SOLVED) Save System Help

I was watching one of Shaun Spaulding's videos so I could figure out how to make a .ini save system. After working for hours I can't seem to figure it out. I either don't get a .ini in my data folder or I get an error for an undefined global variable. Here is the code I am using now, any fix?


Code:
if (file_exists("Save.helix")) file_delete("Save.helix");
        

    ini_open("Save.helix")
    var SavedRoom = room;
    ini_write_real("Room","room",SavedRoom)
    ini_write_real("Player","LevelPoints",global.xp)
    ini_write_real("Player","Health",global.hp)
    ini_write_real("Player","MaxHP",global.maxhp)
    ini_write_real("Player","HPLevel",global.hlvl)
    ini_write_real("Player","SkillPoints",global.skill)
    ini_write_real("Player","LuckLevel",global.clvl)
    ini_write_real("Player","Money",global.gold)
    ini_write_real("Player","NeededXP",global.maxxp)
    ini_write_real("Player","LuckMultiplier",global.luck)
    ini_write_real("Player","CritDamage",global.crit)
    ini_write_real("Player","CritPercentage",global.critCount)
    ini_write_real("Player","Level",global.lvl)
    ini_write_real("Items","Soup",global.usesSoup)
    ini_write_real("Items","Kuulaid",global.usesAid)
    ini_write_real("Items","IceCream",global.usesCream)
    ini_close()
 

andev

Member
Welcome to the GMC!
Is that the entirety of the code? Why are all the ini calls indented?

I either don't get a .ini in my data folder
Game maker does this really annoying thing sometimes where it doesn't put the files written in the /local/gamename/ folder, and instead it puts it in the temporary compile folder, something like /local/appdata/gmt_034945

or I get an error for an undefined global variable
If you could post that error here? It might be the reason this isn't working. If the error triggers before ini_close is called, that will be why your file isn't created.
 
Welcome to the GMC!
Is that the entirety of the code? Why are all the ini calls indented?


Game maker does this really annoying thing sometimes where it doesn't put the files written in the /local/gamename/ folder, and instead, it puts it in the temporary compile folder, something like /local/AppData/gmt_034945


If you could post that error here? It might be the reason this isn't working. If the error triggers before ini_close is called, that will be why your file isn't created.
Thank you for responding! First off that is the entirety of the same script. I am not quite sure what you mean by ini calls intended.l could not find a temporary folder for the game. The global variable error would occur if I didn't include a with statement to identify additional regular variables

EDIT: I thought you said intended not indented. (Dyslexia) That's because of the with statement that was once there.
 

andev

Member
I am not quite sure what you mean by ini calls intended.
upload_2018-1-12_22-56-40.png

Usually you'd only do that if you were including all those calls in the "if file exists" check.

The global variable error would occur if I didn't include a with statement to identify additional regular variables
This sounds important, but I'm not sure what you mean. Is the code posted inside a with statement? Can we get a copy of the error message?
 
S

Silver_Mantis

Guest
Code:
if (file_exists("Save.helix")) file_delete("Save.helix");
I'm pretty sure your issue is this line here.

All you need to do to save an ini file is use something like:
ini_open("Save_File.ini");
It will always overwrite the file, and if not created, will automatically create one.
 
View attachment 15701

Usually you'd only do that if you were including all those calls in the "if file exists" check.


This sounds important, but I'm not sure what you mean. Is the code posted inside a with statement? Can we get a copy of the error message?
]
Oddly enough I was not able to replicate the problem. Now all I need to do is find out why my save file isn't loading.

Code:
if (file_exists("Save.helix")) file_delete("Save.helix");

I'm pretty sure your issue is this line here.

All you need to do to save an ini file is use something like:
ini_open("Save_File.ini");
It will always overwrite the file, and if not created, will automatically create one.
I tried this as well still no save data.
 
I'm pretty sure your issue is this line here.

All you need to do to save an ini file is use something like:
ini_open("Save_File.ini");
It will always overwrite the file, and if not created, will automatically create one.
Occasionally I see in my output box that game maker is sending something to a Z:\ Drive this doesn't make sense because I am using a laptop with only one drive. Could it be possible that game maker is trying to store data somewhere that doesn't exist?

EDIT: EX:
Options: Z:\RPG SNES_D621D40A\MainOptions.json
 
S

Silver_Mantis

Guest
Occasionally I see in my output box that game maker is sending something to a Z:\ Drive this doesn't make sense because I am using a laptop with only one drive. Could it be possible that game maker is trying to store data somewhere that doesn't exist?
Hm that could be. I mean it always goes to the same place for me, which is the AppData folder.
Did you check YourName/AppData/Local/YourGame?
 
Hm that could be. I mean it always goes to the same place for me, which is the AppData folder.
Did you check YourName/AppData/Local/YourGame?
I check there at the beginning of every run and at the end. Still, no save data. Would it be possible to use you're save method instead? Or push me in a new direction so I can fix this and move on.
 
S

Silver_Mantis

Guest
I check there at the beginning of every run and at the end. Still, no save data. Would it be possible to use you're save method instead? Or push me in a new direction so I can fix this and move on.
Yeah I'll show you what I've done.

So when my player walks up to the "Save Scribe" Statue and presses the action key, it saves the game via calling a script. (That is the scr_Save(); )
Code:
/// @description Run Collision Script
if (obj_Player_Stats.near_NPC == true)
{
//Change Text variable
//Down
    if (place_meeting(x,y+21,obj_Player))
    {
    obj_Textbox.text = npc_text;
//Check for Press
        if (keyboard_check_pressed(ord("J")) && (sprite_index == spr_Save_Scribe))
        {
//Create Text Instance
            obj_Camera.cutscene_on = true;
            obj_Textbox.show_text = true;
            obj_Textbox.text = npc_text;
          
            if (saving_active == false)
            {
            saving_active = true;
            sprite_index = spr_Save_Scribe_Active;
            image_speed = 1;
//Save Game
            scr_Save();
            }
        }
    } 
}

Next scr_Save goes to work:
Code:
//Open ini
ini_open("Hero_File.ini");

//Map:
ini_write_real("Player", "Map", obj_Map_Counter.map_count);

//Camera Location:
var cam = view_get_camera(0);
var cam_x = camera_get_view_x(cam);
var cam_y = camera_get_view_y(cam);
ini_write_real("Camera", "X", cam_x);
ini_write_real("Camera", "Y", cam_y);
//Text Box Location:
ini_write_real("Text Box", "X", obj_Textbox.x);
ini_write_real("Text Box", "Y", obj_Textbox.y);

//Save Player Location:
ini_write_real("Player", "X", obj_Player.x);
ini_write_real("Player", "Y", obj_Player.y);

//Save Player Stats:
ini_write_real("Player", "Armor", obj_Player_Stats.player_armor);
ini_write_real("Player", "Health", obj_Player_Stats.player_health);
ini_write_real("Player", "Mana", obj_Player_Stats.player_mana);
ini_write_real("Player", "Stamina", obj_Player_Stats.player_stamina);
ini_write_real("Player", "Armor Level", obj_Player_Stats.player_armor_level);

//Save Inventory:
ini_write_real("Orbs", "Number", obj_Inventory.orb_selection_number);
ini_write_real("Items", "Red Potion", obj_Inventory.item_red_potion);
ini_write_real("Items", "Blue Potion", obj_Inventory.item_blue_potion);
ini_write_real("Items", "Armor Kit", obj_Inventory.item_armor_kit);
ini_write_real("Items", "Bread", obj_Inventory.item_bread);
ini_write_real("Items", "Meat", obj_Inventory.item_meat);
ini_write_real("Items", "Home Meal", obj_Inventory.item_homemeal);
ini_write_real("Items", "Water", obj_Inventory.item_water);
ini_write_real("Items", "Wine", obj_Inventory.item_wine);
ini_write_real("Items", "Royal Meal", obj_Inventory.item_royalmeal);
ini_write_real("Sword", "Number", obj_Inventory.item_sword);
ini_write_real("Shield", "Number", obj_Inventory.item_shield);
ini_write_real("Gold", "Number", obj_Inventory.item_gold);

//Close
ini_close();

The only thing I've seen differently for you is that you use global variables, which personally I hate haha. As you can see I just directly called the things I needed to save and that's it.
 
Yeah I'll show you what I've done.

So when my player walks up to the "Save Scribe" Statue and presses the action key, it saves the game via calling a script. (That is the scr_Save(); )
Code:
/// @description Run Collision Script
if (obj_Player_Stats.near_NPC == true)
{
//Change Text variable
//Down
    if (place_meeting(x,y+21,obj_Player))
    {
    obj_Textbox.text = npc_text;
//Check for Press
        if (keyboard_check_pressed(ord("J")) && (sprite_index == spr_Save_Scribe))
        {
//Create Text Instance
            obj_Camera.cutscene_on = true;
            obj_Textbox.show_text = true;
            obj_Textbox.text = npc_text;
         
            if (saving_active == false)
            {
            saving_active = true;
            sprite_index = spr_Save_Scribe_Active;
            image_speed = 1;
//Save Game
            scr_Save();
            }
        }
    }
}

Next scr_Save goes to work:
Code:
//Open ini
ini_open("Hero_File.ini");

//Map:
ini_write_real("Player", "Map", obj_Map_Counter.map_count);

//Camera Location:
var cam = view_get_camera(0);
var cam_x = camera_get_view_x(cam);
var cam_y = camera_get_view_y(cam);
ini_write_real("Camera", "X", cam_x);
ini_write_real("Camera", "Y", cam_y);
//Text Box Location:
ini_write_real("Text Box", "X", obj_Textbox.x);
ini_write_real("Text Box", "Y", obj_Textbox.y);

//Save Player Location:
ini_write_real("Player", "X", obj_Player.x);
ini_write_real("Player", "Y", obj_Player.y);

//Save Player Stats:
ini_write_real("Player", "Armor", obj_Player_Stats.player_armor);
ini_write_real("Player", "Health", obj_Player_Stats.player_health);
ini_write_real("Player", "Mana", obj_Player_Stats.player_mana);
ini_write_real("Player", "Stamina", obj_Player_Stats.player_stamina);
ini_write_real("Player", "Armor Level", obj_Player_Stats.player_armor_level);

//Save Inventory:
ini_write_real("Orbs", "Number", obj_Inventory.orb_selection_number);
ini_write_real("Items", "Red Potion", obj_Inventory.item_red_potion);
ini_write_real("Items", "Blue Potion", obj_Inventory.item_blue_potion);
ini_write_real("Items", "Armor Kit", obj_Inventory.item_armor_kit);
ini_write_real("Items", "Bread", obj_Inventory.item_bread);
ini_write_real("Items", "Meat", obj_Inventory.item_meat);
ini_write_real("Items", "Home Meal", obj_Inventory.item_homemeal);
ini_write_real("Items", "Water", obj_Inventory.item_water);
ini_write_real("Items", "Wine", obj_Inventory.item_wine);
ini_write_real("Items", "Royal Meal", obj_Inventory.item_royalmeal);
ini_write_real("Sword", "Number", obj_Inventory.item_sword);
ini_write_real("Shield", "Number", obj_Inventory.item_shield);
ini_write_real("Gold", "Number", obj_Inventory.item_gold);

//Close
ini_close();

The only thing I've seen differently for you is that you use global variables, which personally I hate haha. As you can see I just directly called the things I needed to save and that's it.
Thank You! I will reply back with what happened and I'll try your method of approch.
 
S

Silver_Mantis

Guest
Thank You! I will reply back with what happened and I'll try your method of approch.
No problem.
I also noticed you're missing a few " ; " symbols at the end of your lines.
You always want to complete the line with it, or some weird stuff can happen.
 
Top