Legacy GM need help with saving and loading stats!

E

EZTALES

Guest
so i want to save my stats in gamemaker but when i restart the game even when saving it will not save th current stats (still a bit of a noob at saving so im using a drag and drop system) my game uses physics so what im doing is that when you save the game you go to a non physics room and save there but the trouble is saving stats because im only using the basic build in save system my code is down below. please help! any examples would be greatly accepted!
( PLAYER, collide event )
/// collect exp
with (other) {instance_destroy();}
with (obj_player_stats) {
expr += 1;
/// Level Up Code
if (expr >= maxexpr) {
level += 1;
expr = expr-maxexpr;
maxexpr *= 2;
}

}
(PLAYER STATS)
(create event)

/// stats
level = 1;
expr = 0;
maxexpr = 3;

(DRAW GUI EVENT)
/// draw_stats
draw_set_color(c_black);
draw_set_halign(fa_center);
draw_set_font(font_score);
draw_text(68, 33, "LEVEL: " + string(level));
Please write back :)
 

2Dcube

Member
The simplest way, I think, is to save stats into an ini file.

Put this in a script called "scrSave"
Code:
///scrSave()

ini_open("save.ini");
ini_write_real("SAVEDATA", "level", level);
ini_close();
and "scrLoad"
Code:
///scrLoad()

ini_open("save.ini");
level = ini_read_real("SAVEDATA", "level", 1); //1, here, is the default value in case it can't find it
ini_close();
Make sure to call scrLoad after you initialize "level" in the Player Create Event. Save any time "level" changes.
 
E

EZTALES

Guest
The simplest way, I think, is to save stats into an ini file.

Put this in a script called "scrSave"
Code:
///scrSave()

ini_open("save.ini");
ini_write_real("SAVEDATA", "level", level);
ini_close();
and "scrLoad"
Code:
///scrLoad()

ini_open("save.ini");
level = ini_read_real("SAVEDATA", "level", 1); //1, here, is the default value in case it can't find it
ini_close();
Make sure to call scrLoad after you initialize "level" in the Player Create Event. Save any time "level" changes.
Cool! But I got one more question for You! If I wanted to start a new game, instead of loading for instance, how would I restart those values
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Cool! But I got one more question for You! If I wanted to start a new game, instead of loading for instance, how would I restart those values
WHen someone presses the new game button, simply call file_delete() on the ini file. If it's not there, then the default values will be used when you try to read from it.
 
E

EZTALES

Guest
WHen someone presses the new game button, simply call file_delete() on the ini file. If it's not there, then the default values will be used when you try to read from it.
Make sure to call scrLoad after you initialize "level" in the Player Create Event. Save any time "level" changes.
do you guys have any idea how to write this in code? sorry still a real noob at this, does he mean my player stats or player create?
i can write my players create event if you need it please write back
 

2Dcube

Member
(PLAYER STATS)
(create event)
Code:
/// stats
level = 1;
expr = 0;
maxexpr = 3;
scrLoad(); // load here
Any time "level" is changed in your code, for example when the player level goes up:
level = level + 1;
After that line, write
Code:
scrSave();
 
E

EZTALES

Guest
(PLAYER STATS)
(create event)
Code:
/// stats
level = 1;
expr = 0;
maxexpr = 3;
scrLoad(); // load here
Any time "level" is changed in your code, for example when the player level goes up:
level = level + 1;
After that line, write
Code:
scrSave();
thanks so much man!
 
E

EZTALES

Guest
Hey man this worked perfectly but could there be a way to change the main players sprite when you level increases? Please give feedback soon
 
Top