• 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!

GML Problem with array usage in .ini files

D

Dazai

Guest
// SAVE:

ini_write_real("game", "item_array_length", array_length_1d(game.item));

for(i = 0; i < array_length_1d(game.item); i++){
ini_write_real("game", "item[" + string(i) + "].type", game.item.type);
}

// LOAD:

for(i = 0; i < array_length_1d(ini_read_real("game", "item_array_length", 14)); i++){
game.item.type = ini_read_real("game", "item[" + string(i) + "].type", 0);
}



For some reason everything works in my .ini files except when I try to do arrays like this. I suspect it's because of the + string(i) + that I'm doing. Does anybody know why this won't work?

EDIT: Already solved. It was the additional array_length_1d in the LOAD loop. Removing that solved the problem. Mods feel free to delete this!
 

jo-thijs

Member
This part is wrong:
Code:
 i < array_length_1d(ini_read_real("game", "item_array_length", 14));
You're not reading an array from the ini file, but the length of an array.
Applying the function array_length_1d on that will return 0, causing nothing to load.

Also, you should put your code in a code box next time, it took me a bit to realize the array indices were missing
because of the GMC interpreting them as italic text BB codes (or whatever they're called).
 
Top