• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows Loading_Script not functioning right... HELP? :(

N

NanoX93

Guest
I'm having trouble with Loading a savegame out of an ini file. I especially want to save and load the iventories content.

Here is my Saving Script:
_____________________________________________________________________________

if (global.savegame != 0)
{
//Saving required Variables
ini_open("savegame" + string(global.savegame) + ".sav")
ini_write_string("stats","name",global.name);
ini_write_real("stats","money",global.money);
ini_write_real("stats","level",global.level);
//Saving Inventory
for (e = 0;e < global.rows_main; e += 1)
{
inventory_e += 1
for (i = 0; i < global.maxitems_main; i += 1)
{
inventory_i += 1
ini_write_real("inventory",string(inventory_i) + "," + string(inventory_e),global.inventory_main[i,e])
if (global.inventory_main[i,e] != -1)
{
draw_sprite(spr_items,global.inventory_main[i,e],x+(i*132),y+(e*132))
}
}
}
ini_close();
}


_____________________________________________________________________________


And here is the loading script:

_____________________________________________________________________________


if (room == rm_loadgame and global.savegame != 0)
{
ini_open("savegame" + string(global.savegame) + ".sav");
global.name = ini_read_string("stats","name","ERROR");
global.money = ini_read_real("stats","money",0);
global.level = ini_read_real("stats","level",0);
//Saving Inventory
for (e = 0;e < global.rows_main; e += 1)
{
inventory_e += 1
for (i = 0; i < global.maxitems_main; i += 1)
{
inventory_i += 1
global.inventory_main[i,e] = ini_read_real("inventory",string(inventory_i) + "," + string(inventory_e),-1)
if (global.inventory_main[i,e] != -1)
{
draw_sprite(spr_items,global.inventory_main[i,e],x+(i*132),y+(e*132))
}
}
}
ini_close();
room_goto(rm_gamemenu);
}

_____________________________________________________________________________

Saving is almost working perfectly but when it gets to loading the inventory it simply sets every position of the twodimensional inventory array to -1
(-1 = no item in slot i,e)

Anybody has any idea what's wrong with my loadingscript ?

Forum not taking tabs as spacer, soz for that!
 

jo-thijs

Member
Hi and welcome to the GMC!

What do you mean with "Saving is ALMOST working"?
What are the values of inventory_i and inventory_e?
Is there some other code that might cause trouble?
 
N

NanoX93

Guest
I probably should use global.inventory instead of using inventory_i right ?
inventory_i and inventory_e are there to determine the number of the slot inside the ini file.

Almost perfectly means that the inventory is saved starting at global.inventory[1,1] instead of 0,0 but this should not influence the fact that there are no items at all loaded into the inventory after game is started.
 

jo-thijs

Member
But where do you reset inventory_i to 1 when the inner for loop ends?
Also, what do you mean with the saving almost works?

EDIT:
Can you also show the contents of the ini file?
 

Stubbjax

Member
Why do you even use inventory_i and inventory_e? You could be simply using the i and e variables, as it does not look like you set the other variables to 0 before iterating, which may be causing the issue.
 
N

NanoX93

Guest
[inventory]
1,1="-1.000000"
2,1="-1.000000"
3,1="-1.000000"
4,1="-1.000000"
5,1="-1.000000"
6,1="-1.000000"
7,1="-1.000000"
8,1="-1.000000"
9,2="-1.000000"
10,2="-1.000000"
11,2="-1.000000"
12,2="-1.000000"
13,2="-1.000000"
14,2="-1.000000"
.
.
.
 
N

NanoX93

Guest
I now realise that youre right. Allthough i have set inventory_e and i to 0 b4 code starts.

This is the whole code:

inventory_i = 0;
inventory_e = 0;

if (room = rm_loadgame)
{
ini_open("options.sav");
ini_write_real("options","cursor",global.cursor);
ini_write_real("options","cursor_questionmark",global.cursor_questionmark);
ini_write_real("options","volume_master",global.mastervolume);
ini_close();
}

ini_open("options.sav");
global.cursor = ini_read_real("options","cursor",ARK);
global.cursor_questionmark = ini_read_real("options","cursor_questionmark",ARK_questionmark);
global.mastervolume = ini_read_real("options","volume_master",1);
ini_close()

//loading adaptive savegame
if (room == rm_loadgame and global.savegame != 0)
{
ini_open("savegame" + string(global.savegame) + ".sav");
global.name = ini_read_string("stats","name","ERROR");
global.money = ini_read_real("stats","money",0);
global.level = ini_read_real("stats","level",0);
//Saving Inventory
for (e = 0;e < global.rows_main; e += 1)
{
inventory_e += 1
for (i = 0; i < global.maxitems_main; i += 1)
{
inventory_i += 1
global.inventory_main[i,e] = ini_read_real("inventory",string(inventory_i) + "," + string(inventory_e),-1)
if (global.inventory_main[i,e] != -1)
{
draw_sprite(spr_items,global.inventory_main[i,e],x+(i*132),y+(e*132))
}
}
}
ini_close();
room_goto(rm_gamemenu);
}
 
N

NanoX93

Guest
global.savegame is set to the required integer before the loading code starts.
I really dont know why this isnt working
 

Stubbjax

Member
You don't reset those two variables before calling the load script though.

It should look like this:

inventory_i = 0;
inventory_e = 0;

if (room = rm_loadgame)
{
ini_open("options.sav");
ini_write_real("options","cursor",global.cursor);
ini_write_real("options","cursor_questionmark",global.cursor_questionmark);
ini_write_real("options","volume_master",global.mastervolume);
ini_close();
}

ini_open("options.sav");
global.cursor = ini_read_real("options","cursor",ARK);
global.cursor_questionmark = ini_read_real("options","cursor_questionmark",ARK_questionmark);
global.mastervolume = ini_read_real("options","volume_master",1);
ini_close()

//loading adaptive savegame
if (room == rm_loadgame and global.savegame != 0)
{
ini_open("savegame" + string(global.savegame) + ".sav");
global.name = ini_read_string("stats","name","ERROR");
global.money = ini_read_real("stats","money",0);
global.level = ini_read_real("stats","level",0);
//Saving Inventory

inventory_i = 0;
inventory_e = 0;


for (e = 0;e < global.rows_main; e += 1)
{
inventory_e += 1
for (i = 0; i < global.maxitems_main; i += 1)
{
inventory_i += 1
global.inventory_main[i,e] = ini_read_real("inventory",string(inventory_i) + "," + string(inventory_e),-1)
if (global.inventory_main[i,e] != -1)
{
draw_sprite(spr_items,global.inventory_main[i,e],x+(i*132),y+(e*132))
}
}
}
ini_close();
room_goto(rm_gamemenu);
}
 
N

NanoX93

Guest
I just solved it >_>. The room was changing before the instance global.inventory_main was created. In the create event of the object_inventory it sets everything to -1 if not inserted by external code. Thanks for your effort anyways. Have a nice day
 
Top