SOLVED help for save

LUCAITA

Member
Hi, I need help for saving the "permadeath" of mobs.

I use this code for permadeath:

in create of mob1stat
GML:
for ( var i = 1 ; i <= 30; i++) {
    for (var j = Room2; j<=Room1;j++)
    {                                 
    enemy[j,i] = false         
    }
}
in step event of mob1

Code:
if num == 0 { // fare solo se num è = 0
    mob1stat.num +=1
    num = mob1stat.num
}
if hp <= 0 {
mob1stat.nemici[room,num]= true
instance_destroy()
}
if (mob1stat.nemici[room,num] == true) {
    instance_destroy()
}
now my problem its how to save the matrix in file. I've tried with ds_grid_create but I've failed

Code:
var save_data = ds_map_create() {
    
    save_data[?"MONEY"] = statuser.money   
    save_data[?"provenineza"] = statuser.provenienza   
    save_data[?"userhp"] = statuser.userhp
 
    
    ..... ..... .....
    
    
    save_data[?"level"] = statuser.level
    
    
    
  
    var save_string = json_encode(save_data)
    ds_map_destroy(save_data)       
    save_string = base64_encode(save_string)


    var file = file_text_open_write(working_directory + "tutorial.txt")
    file_text_write_string(file, save_string)
    file_text_close(file)
can someone help me?
 

chamaeleon

Member
If you want to store an array as part of JSON serialization, I recommend switching over to using structs instead of ds_map.
GML:
var a = [[true, false, true], [false, true, false]];
var b = { foo: "abc", bar: a, baz: "def" };
show_debug_message(json_stringify(b));
var c = json_parse(json_stringify(b));
show_debug_message(c);
Code:
{ "foo": "abc", "bar": [ [ 1.0, 0.0, 1.0 ], [ 0.0, 1.0, 0.0 ] ], "baz": "def" }
{ foo : "abc", bar : [ [ 1,0,1 ],[ 0,1,0 ] ], baz : "def" }
 
What are you trying to achieve, on this line here? Affect every monster in every room?
GML:
  for (var j = Room2; j<=Room1;j++)
For multiple reasons, I'm 99.999999% sure this won't do what you think it will.

On top of being shaky code, the room order seems inverted by default, when assigned it's index
GML:
show_debug_message(string(Room1));    //Returns 2, IN MY PARTICULAR CASE
show_debug_message(string(Room2));    //Returns 1, IN MY PARTICULAR CASE
show_debug_message(string(Room3));    //Returns 0, IN MY PARTICULAR CASE
 
Last edited:

chamaeleon

Member
Following up what @Slow Fingers says, it is a very bad idea to use room ids as numbers and perform arithmetic on them. Just don't do that. Comparison is ok, adding or subtracting is no-no despite gms not complaining about it.
 
Top