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

Save from 3 different files using an INI file

B

Blakkid489

Guest
So lets say I have these three save files.



My goal is to have the player load the game from where ever they save it too.
I use the code...
Code:
ini_write_real(Save1,"coins",global.coins);
and....
Code:
ini_read_real("Save1","coins",0);
So what if the player wants to save on file 2 or 3?
 

obscene

Member
Well you use a variable instead of Save1. When they pick a different slot you set your variable to whatever is correct or you add a number to a string to come up with the correct file name.
 

Joe Ellis

Member
a simple way is to set each save slot to save a different filename, and match them with the load ones

and if you want more than 3, like all the save games have a different save icon,

you can use file_find_first

Code:
var a;
xx=where the first icon goes
yy=where the first icon goes
file = file_find_first("*.ini", 0)

if string_length(file)!=0 ///if an ini file was found
{
a=instance_create(xx,yy,Saveobj) ///create first save game icon
a.file=file ///set the icons file to the one just found


do ///repeat till its got all the save games
{
file = file_find_next() ///find next file
if string_length(file)!=0 ///if there is one
{
xx+=where the next icon goes ///move across a space
if xx>where the first row is full ///if it gets to the end of the row
{
xx=start of the next row ///start a new one
yy+=next row ///move down a space
}
a=instance_create(xx,yy,Saveobj) ///create next icon
a.file=file ///set its file
}
}
until(string_length(file)=0) ///until theres none left
}
then to load from each icon do

Code:
ini_read_real(file,"coins",0)
in the click or whatever event when an icon is selected

same with saving

Code:
ini_write_real(file,"coins",global.coins)
and if you want to let the user save to a new file

add an icon for new save at the start or end of the list of icons, or anywhere

make it create a text input box so they can save it as whatever they want
and it'll show up in the list the next time you open the load screen
or if you want it to just have a number
do file find again
but instead of creating objects just increase a temp variable "count" by 1 each time it finds a file
then call the save "Save"+string(count+1)

I know you might not want all of this, I'm just showing you a few different possibilities

If you wanna know how to make a text input box just let me know
 
Last edited:
B

Blakkid489

Guest
Well you use a variable instead of Save1. When they pick a different slot you set your variable to whatever is correct or you add a number to a string to come up with the correct file name.
Hmmm seems simple enough

a simple way is to set each save slot to save a different filename, and match them with the load ones

and if you want more than 3, like all the save games have a different save icon,

you can use file_find_first

Code:
var a;
xx=where the first icon goes
yy=where the first icon goes
file = file_find_first("*.ini", 0)

if string_length(file)!=0 ///if an ini file was found
{
a=instance_create(xx,yy,Saveobj) ///create first save game icon
a.file=file ///set the icons file to the one just found


do ///repeat till its got all the save games
{
file = file_find_next() ///find next file
if string_length(file)!=0 ///if there is one
{
xx+=where the next icon goes ///move across a space
if xx>where the first row is full ///if it gets to the end of the row
{
xx=start of the next row ///start a new one
yy+=next row ///move down a space
}
a=instance_create(xx,yy,Saveobj) ///create next icon
a.file=file ///set its file
}
}
until(string_length(file)=0) ///until theres none left
}
then to load from each icon do

Code:
ini_read_real(file,"coins",0)
in the click or whatever event when an icon is selected

same with saving

Code:
ini_write_real(file,"coins",global.coins)
and if you want to let the user save to a new file

add an icon for new save at the start or end of the list of icons, or anywhere

make it create a text input box so they can save it as whatever they want
and it'll show up in the list the next time you open the load screen
or if you want it to just have a number
do file find again
but instead of creating objects just increase a temp variable "count" by 1 each time it finds a file
then call the save "Save"+string(count+1)

I know you might not want all of this, I'm just showing you a few different possibilities

If you wanna know how to make a text input box just let me know

I see what you did there lol I have a text input box but I'll htrow some code and test this out first
 
Top