P
prestidigitator
Guest
Hi everyone,
I have two problems with HIGHSCORE
1.
He only writes one record of my scores to HIGHSCORE, but should save me my TOP 10 scores.
I've already checked if the save file to HIGHSCORE exists..and this file is there.
2.
When I load the game and then quit the game and go to the HIGHSCORE room, the only result that saves disappears and nothing appears
Maybe one of you will guide me to what I'm doing wrong ... thank you
Here below code
scripts
score_add
score_save[/B]
score_sort
obj_highscore (perssistent) in the first game room before the game starts
creacion code room
obj_game_manager
step
obj_menu
step
I have two problems with HIGHSCORE
1.
He only writes one record of my scores to HIGHSCORE, but should save me my TOP 10 scores.
I've already checked if the save file to HIGHSCORE exists..and this file is there.
2.
When I load the game and then quit the game and go to the HIGHSCORE room, the only result that saves disappears and nothing appears
Maybe one of you will guide me to what I'm doing wrong ... thank you
Here below code
scripts
score_add
GML:
///score_add(name,score)
if(ds_exists(highscores, ds_type_list)) {
var m=ds_map_create();
m[?"name"]=argument0
m[?"score"]=argument1
ds_list_add(highscores, m)
ds_list_mark_as_map(highscores, ds_list_size(highscores)-1)
score_sort()
if(ds_list_size(highscores)>10) {
ds_list_delete(highscores,10)
}
}
[B]
GML:
///score_save
var f=file_text_open_write("save.dat");
if(f>-1) {
var m=ds_map_create();
ds_map_add_list(m,"default",highscores)
var s=json_encode(m);
file_text_write_string(f,s)
file_text_close(f)
//ds_map_destroy(m)
}
GML:
///score_sort
if(ds_exists(highscores, ds_type_list) && ds_list_size(highscores)>1) {
for(var _i=ds_list_size(highscores)-2; _i>=0; _i--) {
var m1=highscores[|_i];
var m2=highscores[|_i+1];
if(m1[?"score"]<m2[?"score"]) {
ds_list_replace(highscores,_i,m2)
ds_list_replace(highscores,_i+1,m1)
ds_list_mark_as_map(highscores, _i)
ds_list_mark_as_map(highscores, _i+1)
}
}
obj_highscore (perssistent) in the first game room before the game starts
creacion code room
GML:
global.Score=0
globalvar highscores;
highscores=ds_list_create()
//Load points from disk
var f=file_text_open_read("save.dat")
if(f>-1) {
var s=file_text_read_string(f)
//show_debug_message(s)
s=json_decode(s)
if(s!=-1 && ds_exists(s, ds_type_map) && ds_map_exists(s,"default")) {
var m=s[?"default"];
for(var _i=0; _i<ds_list_size(m); _i++) {
if(ds_exists(m[|_i], ds_type_map)) {
var _m=ds_map_create();
ds_map_copy(_m, m[|_i])
ds_list_insert(highscores, _i, _m)
ds_list_mark_as_map(highscores, _i)
}
}
}
ds_map_destroy(s)
file_text_close(f)
}
obj_game_manager
step
GML:
if (global.life <= 0)
{
if (can_finish == false)
{
if (alarm[0] == -1) { // only start when it's not already counting down
alarm[0] = 120; //
}
} else {
if (global.Score >= 500) //the condition must be met to write the minimum result to the table
{
var s=highscores[| ds_list_size(highscores) - 1];
//Do the points qualify for the top 10
if (ds_list_size(highscores) < 10 || s[?"score"] <= global.Score) {
room_goto(rm_save_score);
exit; // complete the execution of the step event in this frame
}
}
room_goto(rm_game_over);
}
}
obj_menu
step
GML:
if keyboard_check_pressed(vk_enter) {
if(selected=0) {
room_goto(room_stage1)
} else if(selected=1) {
if(file_exists("save.dat")){
game_load( "Save.dat" );
} else {
show_message("Cannot find Save.dat file. Please start a new game.");
}
audio_stop_sound (sounds_global);
} else if(selected=2) {
room_goto(room_highscore)
} else if(selected=3) {
room_goto(room_options)
} else if(selected=4) {
room_goto(room_credits)
} else if(selected=5) {
game_end()
}
}
Last edited by a moderator: