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

[SOLVED]Save procedure

Ok So. I tried commenting out the ds_list and it freezes completely again this time at the following:

Code:
        JSONInstance = json_encode(instanceMap);
Out of the following code:

Code:
var brain_master_count = instance_number(BrainMaster);

if (file_exists("brain_master.sav"))
{
    file_delete("brain_master.sav");
    
}

var saveFile = file_text_open_write("brain_master.sav");



for (var i = 0; i< brain_master_count;i++)
{
        var instance = instance_find(BrainMaster, i);
        
        //convert instance to a ds_map
        var instanceMap = ds_map_create();
        //var list1 =  ds_list_create();
        //
            
        ds_map_add(instanceMap, "timer", instance.timer);
        ds_map_add(instanceMap, "global-max_number_of_brains", global.max_number_of_brains);   
        ds_map_add(instanceMap, "global-number_of_brains_on_screen", global.number_of_brains_on_screen);
        ds_map_add(instanceMap, "global-creating_brain", global.creating_brain);
        
        ds_map_add(instanceMap, "global-frank_timer", global.frank_timer);
        ds_map_add(instanceMap, "global-delay_between_brains", global.delay_between_brains);
        ds_map_add(instanceMap, "frank_audio_timer", instance.frank_audio_timer);
        ds_map_add(instanceMap, "timer", instance.sprite_index);
        ds_map_add(instanceMap, "door", instance.door);
        ds_map_add(instanceMap, "door_timer", instance.door_timer);
        ds_map_add(instanceMap, "sprite_index", instance.sprite_index);
        
        ds_map_add(instanceMap, "game_win_flag", instance.game_win_flag);
        ds_map_add(instanceMap, "f_timer", instance.f_timer);
        ds_map_add(instanceMap, "g_timer", instance.g_timer);
        ds_map_add(instanceMap, "f_flag", instance.f_flag);
        ds_map_add(instanceMap, "global-current_level", global.current_level);

        ds_map_add(instanceMap, "global-you_lose", global.you_lose);
        ds_map_add(instanceMap, "random_y", instance.random_y);


        ds_map_add(instanceMap, "frank_audio_timer", instance.frank_audio_timer);
        ds_map_add(instanceMap, "f_timer", instance.f_timer);
        ds_map_add(instanceMap, "g_timer", instance.g_timer);
If you look though, the JSONString is is right.
upload_2019-3-29_12-42-47.png
 
This might be stating the bleeding obvious, but does your game freeze when you don't run it in debug mode?

Because you've got a breakpoint sitting active on line 55 of your code in the screenshot, so the debugger is seeing that and breaking at the next line of code which happens to be the one highlighted.
 
Yes, unfortunately it freezes when I'm not in debug mode. Any idea why the instanceMap is 0? And if the JSON string is populated why is it throwing an error on the
Code:
JSONInstance = json_encode(instanceMap);
This is the entire code, I think I left some out last post.
Code:
var brain_master_count = instance_number(BrainMaster);

if (file_exists("brain_master.sav"))
{
    file_delete("brain_master.sav");
   
}

var saveFile = file_text_open_write("brain_master.sav");



for (var i = 0; i< brain_master_count;i++)
{
        var instance = instance_find(BrainMaster, i);
       
        //convert instance to a ds_map
        var instanceMap = ds_map_create();
        //var list1 =  ds_list_create();
        //
           
        ds_map_add(instanceMap, "timer", instance.timer);
        ds_map_add(instanceMap, "global-max_number_of_brains", global.max_number_of_brains);  
        ds_map_add(instanceMap, "global-number_of_brains_on_screen", global.number_of_brains_on_screen);
        ds_map_add(instanceMap, "global-creating_brain", global.creating_brain);
       
        ds_map_add(instanceMap, "global-frank_timer", global.frank_timer);
        ds_map_add(instanceMap, "global-delay_between_brains", global.delay_between_brains);
        ds_map_add(instanceMap, "frank_audio_timer", instance.frank_audio_timer);
        ds_map_add(instanceMap, "timer", instance.sprite_index);
        ds_map_add(instanceMap, "door", instance.door);
        ds_map_add(instanceMap, "door_timer", instance.door_timer);
        ds_map_add(instanceMap, "sprite_index", instance.sprite_index);
       
        ds_map_add(instanceMap, "game_win_flag", instance.game_win_flag);
        ds_map_add(instanceMap, "f_timer", instance.f_timer);
        ds_map_add(instanceMap, "g_timer", instance.g_timer);
        ds_map_add(instanceMap, "f_flag", instance.f_flag);
        ds_map_add(instanceMap, "global-current_level", global.current_level);

        ds_map_add(instanceMap, "global-you_lose", global.you_lose);
        ds_map_add(instanceMap, "random_y", instance.random_y);


        ds_map_add(instanceMap, "frank_audio_timer", instance.frank_audio_timer);
        ds_map_add(instanceMap, "f_timer", instance.f_timer);
        ds_map_add(instanceMap, "g_timer", instance.g_timer);
   


        //ds_list_add(list1, object_get_name(FrankensteinIdleObject), FrankensteinIdleObject.object_index);
        //ds_map_add_list(instanceMap, "list", list1);
        //ds_list_add(list1, object_get_name(CastleDoorObject), CastleDoorObject.object_index);
        //ds_list_add(list1, object_get_name(LaserBrainObject), LaserBrainObject.object_index);



        //convert this map into json
        JSONInstance = json_encode(instanceMap);
       
        file_text_write_string(saveFile, JSONInstance);
       
        //seperate with pipe character
        file_text_write_string(saveFile, "|");
       
        ds_map_destroy(instanceMap);      
        //ds_list_destroy(list1);



}

///close the file
file_text_close(saveFile);


///////
Edit: It doesn't throw an error on the JSON statement, it just freezes
 
Any idea why the instanceMap is 0?
Not sure why it's freezing, but as for the instanceMap being 0. GMS re-uses indexes for ds_ datastructures.

So you create a ds_map, it gets an index of 0, then you destroy it after you've used it, which frees up index 0 for re-use when you create the next ds_map in your for() loop.

EDIT: I notice you are adding the keys "timer" and "frank_audio_timer" to the map twice each. You should use different keys. Not sure if that's causing the issue, but its something to fix.
 
Last edited:
T

Taddio

Guest
Yeah, no two keys should be the sanne in a map. g_timer and f_timer are called twice
 

chamaeleon

Member
Well I got rid of the doubles and it is still freezing! God, this is so frustrating.
There is nothing inherently wrong with the code. If someone had a project that had objects and instances with the names you use, your code should work just fine. Are you able to produce a standalone example of this problem, the ideal case being a single script that is self-contained..
 
The following script freezes as well.

Code:
var brain_master_count = instance_number(BrainMaster);

if (file_exists("brain_master.sav"))
{
    file_delete("brain_master.sav");
    
}

var saveFile = file_text_open_write("brain_master.sav");



for (var i = 0; i< brain_master_count;i++)
{
        var instance = instance_find(BrainMaster, i);
        
        //convert instance to a ds_map
        var instanceMap = ds_map_create();
        //var list1 =  ds_list_create();
        //
            
        //ds_map_add(instanceMap, "timer", instance.timer);
        ds_map_add(instanceMap, "global-max_number_of_brains", global.max_number_of_brains);   
        /************************
        ds_map_add(instanceMap, "global-number_of_brains_on_screen", global.number_of_brains_on_screen);
        ds_map_add(instanceMap, "global-creating_brain", global.creating_brain);
        
        ds_map_add(instanceMap, "global-frank_timer", global.frank_timer);
        ds_map_add(instanceMap, "global-delay_between_brains", global.delay_between_brains);
        ds_map_add(instanceMap, "frank_audio_timer", instance.frank_audio_timer);
        ds_map_add(instanceMap, "timer", instance.sprite_index);
        ds_map_add(instanceMap, "door", instance.door);
        ds_map_add(instanceMap, "door_timer", instance.door_timer);
        ds_map_add(instanceMap, "sprite_index", instance.sprite_index);
        
        ds_map_add(instanceMap, "game_win_flag", instance.game_win_flag);
        ds_map_add(instanceMap, "f_timer", instance.f_timer);
        ds_map_add(instanceMap, "g_timer", instance.g_timer);
        ds_map_add(instanceMap, "f_flag", instance.f_flag);
        ds_map_add(instanceMap, "global-current_level", global.current_level);

        ds_map_add(instanceMap, "global-you_lose", global.you_lose);
        ds_map_add(instanceMap, "random_y", instance.random_y);


        //ds_map_add(instanceMap, "frank_audio_timer", instance.frank_audio_timer);
        //ds_map_add(instanceMap, "f_timer", instance.f_timer);
        //ds_map_add(instanceMap, "g_timer", instance.g_timer);
    


        //ds_list_add(list1, object_get_name(FrankensteinIdleObject), FrankensteinIdleObject.object_index);
        //ds_map_add_list(instanceMap, "list", list1);
        //ds_list_add(list1, object_get_name(CastleDoorObject), CastleDoorObject.object_index);
        //ds_list_add(list1, object_get_name(LaserBrainObject), LaserBrainObject.object_index);


***************************/
        //convert this map into json
        JSONInstance = json_encode(instanceMap);
        
        file_text_write_string(saveFile, JSONInstance);
        
        //seperate with pipe character
        file_text_write_string(saveFile, "|");
        
        ds_map_destroy(instanceMap);       
        //ds_list_destroy(list1);



}
 

chamaeleon

Member
The following script freezes as well.
I said standalone because no one besides you have the brain object, the instance, and the global variables you use. I think everyone would be able to help more if you were able to provide code that shows a problem, code that can be pasted into a blank project, ideally. At the moment, all people can do is read the code you show and say, "that looks correct, it should work".

For instance, did you try a blank project of your own and paste the code I posted on the first page in the thread? Did it work or hang?
 
@chamaeleon
I said standalone because no one besides you have the brain object, the instance, and the global variables you use. I think everyone would be able to help more if you were able to provide code that shows a problem, code that can be pasted into a blank project, ideally. At the moment, all people can do is read the code you show and say, "that looks correct, it should work".

For instance, did you try a blank project of your own and paste the code I posted on the first page in the thread? Did it work or hang?
So I tried a blank project of my own and pasted the code you posted on the first page. It didn't freeze. And I think it worked? (check the screenshot).

upload_2019-3-31_17-8-23.png

So what does this tell us? (see below)
 
Code:
/// @description Insert description here
// You can write your code in this editor
/// @description Insert description here
// You can write your code in this editor
if (file_exists("json.sav")) {
    file_delete("json.sav");
}

var saveFile = file_text_open_write("json.sav");
var map = ds_map_create();
ds_map_add(map, "foo", 123);
ds_map_add(map, "bar", 456);
var json = json_encode(map);
file_text_write_string(saveFile, json);
ds_map_destroy(map);
file_text_close(saveFile);
I'm betting on something being put in the ds_map that it doesn't like for some reason. Consensus?
 

chamaeleon

Member
I'm betting on something being put in the ds_map that it doesn't like for some reason. Consensus?
First of all, you agree the my example is a trimmed down example that does almost everything your own code does, so for arguments sake it is essentially equivalent? It seems to have worked well enough (giving the same output I get).

I think the only thing I don't really do is utilize an instance to get the data from for my small ds_map. So, having said that.. If your instance is a valid instance, and the instance variables you are storing in the ds_map are simple numbers (until you uncomment the ds_list code you have disabled), I can't think of any data that you explicitly store in the ds_map that would cause any issue.

What happens if you comment out the json_encode() call (at least I assume that is where you say the program hangs/freezes), and simply assign any string value to JSONinstance instead of calling json_encode()?

Incidentally, I see now that JSONinstance becomes an instance variable instead of a local variable like most of the other variables you use in your code. It shouldn't make a difference, but I wonder what happens if you add var in front of it.
 
Well @chamaeleon this is peculiar. It froze when I assigined var JSONInstance = "some string"

Code:
var brain_master_count = instance_number(BrainMaster);

if (file_exists("brain_master.sav"))
{
    file_delete("brain_master.sav");
    
}

var saveFile = file_text_open_write("brain_master.sav");



for (var i = 0; i< brain_master_count;i++)
{
        var instance = instance_find(BrainMaster, i);
        
        //convert instance to a ds_map
        var instanceMap = ds_map_create();
        //var list1 =  ds_list_create();
        //
            
        //ds_map_add(instanceMap, "timer", instance.timer);
        ds_map_add(instanceMap, "global-max_number_of_brains", global.max_number_of_brains);   
        /************************
        ds_map_add(instanceMap, "global-number_of_brains_on_screen", global.number_of_brains_on_screen);
        ds_map_add(instanceMap, "global-creating_brain", global.creating_brain);
        
        ds_map_add(instanceMap, "global-frank_timer", global.frank_timer);
        ds_map_add(instanceMap, "global-delay_between_brains", global.delay_between_brains);
        ds_map_add(instanceMap, "frank_audio_timer", instance.frank_audio_timer);
        ds_map_add(instanceMap, "timer", instance.sprite_index);
        ds_map_add(instanceMap, "door", instance.door);
        ds_map_add(instanceMap, "door_timer", instance.door_timer);
        ds_map_add(instanceMap, "sprite_index", instance.sprite_index);
        
        ds_map_add(instanceMap, "game_win_flag", instance.game_win_flag);
        ds_map_add(instanceMap, "f_timer", instance.f_timer);
        ds_map_add(instanceMap, "g_timer", instance.g_timer);
        ds_map_add(instanceMap, "f_flag", instance.f_flag);
        ds_map_add(instanceMap, "global-current_level", global.current_level);

        ds_map_add(instanceMap, "global-you_lose", global.you_lose);
        ds_map_add(instanceMap, "random_y", instance.random_y);


        //ds_map_add(instanceMap, "frank_audio_timer", instance.frank_audio_timer);
        //ds_map_add(instanceMap, "f_timer", instance.f_timer);
        //ds_map_add(instanceMap, "g_timer", instance.g_timer);
    


        //ds_list_add(list1, object_get_name(FrankensteinIdleObject), FrankensteinIdleObject.object_index);
        //ds_map_add_list(instanceMap, "list", list1);
        //ds_list_add(list1, object_get_name(CastleDoorObject), CastleDoorObject.object_index);
        //ds_list_add(list1, object_get_name(LaserBrainObject), LaserBrainObject.object_index);


***************************/
        //convert this map into json
        //var JSONInstance = json_encode(instanceMap);
        var JSONInstance = "this is a test string";
        
        file_text_write_string(saveFile, JSONInstance);
        
        //seperate with pipe character
        file_text_write_string(saveFile, "|");
        
        ds_map_destroy(instanceMap);       
        //ds_list_destroy(list1);



}

///close the file
file_text_close(saveFile);


///////
 
I supposed a question that has not been asked yet is which event is this code in? And can you also put show_debug_message() calls in the loop so you can see how often it is getting called and whether it is the for loop that is locking it up, or if it is something else?
 
Code:
var brain_master_count = instance_number(BrainMaster);

if (file_exists("brain_master.sav"))
{
    file_delete("brain_master.sav");
    
}

show_debug_message("Opening the save file for writing");

var saveFile = file_text_open_write("brain_master.sav");

show_debug_message("ENtering for loop");
show_debug_message("Brain Master Count is " + string(brain_master_count));

for (var i = 0; i< brain_master_count;i++)
{
        var instance = instance_find(BrainMaster, i);
        
        //convert instance to a ds_map
        var instanceMap = ds_map_create();
        //var list1 =  ds_list_create();
        //
            
        show_debug_message("Adding to ds_map");
        //ds_map_add(instanceMap, "timer", instance.timer);
        ds_map_add(instanceMap, "global-max_number_of_brains", global.max_number_of_brains);   
        /************************
        ds_map_add(instanceMap, "global-number_of_brains_on_screen", global.number_of_brains_on_screen);
        ds_map_add(instanceMap, "global-creating_brain", global.creating_brain);
        
        ds_map_add(instanceMap, "global-frank_timer", global.frank_timer);
        ds_map_add(instanceMap, "global-delay_between_brains", global.delay_between_brains);
        ds_map_add(instanceMap, "frank_audio_timer", instance.frank_audio_timer);
        ds_map_add(instanceMap, "timer", instance.sprite_index);
        ds_map_add(instanceMap, "door", instance.door);
        ds_map_add(instanceMap, "door_timer", instance.door_timer);
        ds_map_add(instanceMap, "sprite_index", instance.sprite_index);
        
        ds_map_add(instanceMap, "game_win_flag", instance.game_win_flag);
        ds_map_add(instanceMap, "f_timer", instance.f_timer);
        ds_map_add(instanceMap, "g_timer", instance.g_timer);
        ds_map_add(instanceMap, "f_flag", instance.f_flag);
        ds_map_add(instanceMap, "global-current_level", global.current_level);

        ds_map_add(instanceMap, "global-you_lose", global.you_lose);
        ds_map_add(instanceMap, "random_y", instance.random_y);


        //ds_map_add(instanceMap, "frank_audio_timer", instance.frank_audio_timer);
        //ds_map_add(instanceMap, "f_timer", instance.f_timer);
        //ds_map_add(instanceMap, "g_timer", instance.g_timer);
    


        //ds_list_add(list1, object_get_name(FrankensteinIdleObject), FrankensteinIdleObject.object_index);
        //ds_map_add_list(instanceMap, "list", list1);
        //ds_list_add(list1, object_get_name(CastleDoorObject), CastleDoorObject.object_index);
        //ds_list_add(list1, object_get_name(LaserBrainObject), LaserBrainObject.object_index);


***************************/
        //convert this map into json
        //var JSONInstance = json_encode(instanceMap);
        
        show_debug_message("This is before the JSONInstance assignment");
        
        var JSONInstance = "this is a test string";
        
        show_debug_message("Writing to save file ");
        
        file_text_write_string(saveFile, JSONInstance);
        
        show_debug_message("Writing | to save file");
        
        //seperate with pipe character
        file_text_write_string(saveFile, "|");
        
        
        
        ds_map_destroy(instanceMap);       
        //ds_list_destroy(list1);



}

///close the file
file_text_close(saveFile);

Debug Statements:

Drawing splash screen
Drawing splash screen
Drawing splash screen
Drawing splash screen
Drawing splash screen
Drawing splash screen
Agapite Instances1
Alchemist Timer0
Drawing splash screen
Drawing splash screen
Drawing splash screen
Drawing splash screen
Drawing splash screen
Drawing splash screen
Agapite Instances1
Alchemist Timer0
Drawing splash screen
Drawing splash screen
Drawing splash screen
Drawing splash screen
Drawing splash screen
Drawing splash screen
Opening the save file for writing
ENtering for loop
Brain Master Count is 1
Adding to ds_map
This is before the JSONInstance assignment
Writing to save file
Writing | to save file
Dead Brain Ghost and Fading Gem
The event the script is called in is Left Pressed of the AlchemistTableObject object.

Code:
}
*/

    a_choose = true; //you can choose one thing fromt he alchemist lab       
    
    scr_save_game();
    if (global.alchemist_lock == false)
    {
        room_persistent = true;
        audio_play_sound(AlchemistLabOpenSound, 20, false);
        global.RoomBeforeAlchemist = room;
        room_goto(AlchemistTableRoom);
        draw_set_colour(c_black);   
        
    }
scr_save_game(() is what we are looking at.

-Ted
 
So based on all those show_debug_message() call, it looks to me that it gets all the way through the saving and comes out of the script. Because shows this line:
Writing | to save file
followed by this:
Dead Brain Ghost and Fading Gem
and this line does not appear to be in the script.
To be absolutely sure, put two more show_debug_message() calls, one before this line:
Code:
///close the file
and one after it. That would then confirm that the script is being finished with, and that it may in fact be something else completely different that is causing the game to hang.
 
Code:
show_debug_message("CLosing file...");
///close the file
file_text_close(saveFile);
show_debug_message("FIle CLosed....");

///////
and

output:

Code:
Adding to ds_map
This is before the JSONInstance assignment
Writing to save file
Writing | to save file
CLosing file...
FIle CLosed....
Dead Brain Ghost and Fading Gem
 
That seems to indicate to me that it is not the saving that is causing the hanging to happen. Where does that last line "Dead Brain Ghost and Fading Gem" get written from? That might be the next place to start looking.
 
Dead Brain Ghost
Ok so.

This is the brain script:
Code:
scr_brain_master_save();
scr_frank_monster_save();
scr_simple_brain_save();
scr_laser_brain_save();
scr_scorpion_brain_save();
scr_big_brain_save();
scr_fading_gem_save();
scr_frank_monster_ob_save();
scr_frank_in_idle_save();
scr_sub_master_save();
scr_brain_master_save() is what we have been looking at.

so Dead Brain Ghost and Fading Gem first occurs in the following script: (scr_simple_brain_save)

Code:
var simple_brain_count = instance_number(SimpleBrain);

if (file_exists("simple_brain.sav"))
{
    file_delete("simple_brain.sav");
    
}

var saveFile = file_text_open_write("simple_brain.sav");




for (var i = 0; i< simple_brain_count;i++)
{
        var instance = instance_find(SimpleBrain, i);
        
        //convert instance to a ds_map
        var instanceMap = ds_map_create();
        var list1 =  ds_list_create();
        var list2 = ds_list_create();
        var list3 = ds_list_create();
        var list4 = ds_list_create();
        var list5 = ds_list_create();
        var list6 = ds_list_create();
        //
        
        ds_map_add(instanceMap, "sprite_index", instance.sprite_index);
        ds_map_add(instanceMap, "image_speed", instance.image_speed);
        ds_map_add(instanceMap, "x", instance.x);
        ds_map_add(instanceMap, "y", instance.y);

        
    ///////////////////////////////
        
        //ds_map_add(instanceMap, "brain_master_count", instance.brain_master_count);
        //ds_list_add(list1, object_get_name(global.current_bat), global.current_path.object_index);
        ds_map_add(instanceMap, "hp_minus", instance.hp_minus);
        ds_map_add(instanceMap, "global-castle_hp", global.castle_hp);
        //ds_list_add(list1, object_get_name(floater), floater);
        //ds_list_add(list1,object_get_name(floater.text), floater.text);
        ds_map_add(instanceMap, "castle_collision_timer", instance.castle_collision_timer);

        ds_map_add(instanceMap, "frozen", instance.frozen);
        ds_map_add(instanceMap, "global-petrification", global.petrification);
        ds_map_add(instanceMap, "x", instance.x);
        ds_map_add(instanceMap, "y", instance.y);

        //ds_map_add(instanceMap, "freeze_brains", instance.freeze_brains);
        ds_map_add(instanceMap, "was_hit_by_lit", instance.was_hit_by_lit);
        ds_map_add(instanceMap, "path_speed", instance.path_speed);
        ds_map_add(instanceMap, "speed", instance.speed);
        
        
        ds_map_add(instanceMap, "global-freeze_brains", global.freeze_brains);
        ds_map_add(instanceMap, "image_speed", instance.image_speed);

        ds_map_add(instanceMap, "global-active", global.active);
        ds_map_add(instanceMap, "image_speed", instance.image_speed);
        ds_map_add(instanceMap, "x", instance.x);
        ds_map_add(instanceMap, "y", instance.y);
        ds_map_add(instanceMap, "defense", instance.defense);
        ds_map_add(instanceMap, "mind_timer", instance.mind_timer);
        ds_map_add(instanceMap, "colliding_flag", instance.colliding_flag);
        ds_map_add(instanceMap, "random_num", instance.random_num);
        ds_map_add(instanceMap, "petrify", instance.petrify);
        ds_map_add(instanceMap, "drift", instance.drift);
        ds_map_add(instanceMap, "under_attack", instance.under_attack);
        ds_map_add(instanceMap, "took_a_hit", instance.took_a_hit);
        ds_map_add(instanceMap, "damage_dealt_to_bat", instance.damage_dealt_to_bat);
        ds_map_add(instanceMap, "had_a_collision", instance.had_a_collision);
        ds_map_add(instanceMap, "collision", instance.collision);
        ds_map_add(instanceMap, "can_act", instance.can_act);
        ds_map_add(instanceMap, "mutx", instance.mutx);
        ds_map_add(instanceMap, "using_mutex", instance.using_mutex);
        
        ds_map_add(instanceMap, "global-litorigin_x", global.litorigin_x);
        ds_map_add(instanceMap, "global-litorigin_y", global.litorigin_y);
        ds_map_add(instanceMap, "global-lightning_1_x", global.litorigin_y);
        ds_map_add(instanceMap, "global-lightning_1_y", global.litorigin_y);
        
        ds_map_add(instanceMap, "lit_damage_timera", instance.lit_damage_timera);
        ds_map_add(instanceMap, "hp_minus", instance.hp_minus);
        ds_map_add(instanceMap, "hp", instance.hp);
        
        
        
        ds_map_add(instanceMap, "lit_damage_timera", instance.lit_damage_timera);
        ds_map_add(instanceMap, "under_attack", instance.under_attack);
        ds_map_add(instanceMap, "was_hit_by_lit", instance.was_hit_by_lit);
        ds_map_add(instanceMap, "lit_damage_timera", instance.lit_damage_timera);
        
        ds_map_add(instanceMap, "global-lightning_2_x", global.lightning_2_x);
        ds_map_add(instanceMap, "global-lightning_2_y", global.lightning_2_y);
        
        ds_map_add(instanceMap, "global-lightning_3_x", global.lightning_3_x);
        ds_map_add(instanceMap, "global-lightning_3_y", global.lightning_3_y);

        ds_map_add(instanceMap, "poisoned", instance.poisoned);
        ds_map_add(instanceMap, "timer", instance.timer);
        ds_map_add(instanceMap, "damage", instance.damage);

        show_debug_message("Dead Brain Ghost and Fading Gem");

        ds_list_add(list3, "Dead BrainObject", x, y);
        ds_list_add(list4, "Fading Gem Object", x, y);


        ds_map_add(instanceMap, "global-achievement_gold_counter", global.achievement_gold_counter);
        ds_map_add(instanceMap, "global-achievement_tome_experience", global.achievement_tome_experience);

        ds_map_add(instanceMap, "global-freeze_brains", global.freeze_brains);
    
    
        ds_map_add(instanceMap, "castle_wall_timer", instance.castle_wall_timer);
        ds_map_add(instanceMap, "global-castle_HP", global.castle_hp);
        ds_map_add(instanceMap, "number_of_attacks", instance.number_of_attacks);
    
    
        //ds_list_add(list5, object_get_name(floater), x,y);
        //ds_list_add(list5, object_get_name(floater_text), x, y);
        
        ds_map_add(instanceMap, "mind_timer",  instance.mind_timer);       
        ds_map_add(instanceMap, "global-mindbreak", global.mindbreak);
        ds_map_add(instanceMap, "path_number", instance.path_index);
        
        ds_map_add(instanceMap, "still", instance.still);
        
        ds_list_add(list6, "Collisions", "BombBatObject","DraculaInnerTubeObject",
                        "DraculasCastleObject", "LightningBatObject", "MagicBatObject",
                        "PoisonBatObject","SentryBatObject", "SnowballObject"    ,
                        "SnowBatObject", "SonicBoomObject", "SpitObject",
                            "WindBatObject");               
        

        //convert this map into json
        JSONInstance = json_encode(instanceMap)
        JSONList = json_encode(list1);
        JSONList2 = json_encode(list2);
        JSONList3 = json_encode(list3);
        JSONList4 = json_encode(list4);
        JSONList5 = json_encode(list5);
        JSONList6 = json_encode(list6);
        file_text_write_string(saveFile, JSONInstance);
        file_text_write_string(saveFile, JSONList);
        file_text_write_string(saveFile, JSONList2);
        file_text_write_string(saveFile, JSONList3);
        file_text_write_string(saveFile, JSONList4);
        file_text_write_string(saveFile, JSONList5);
        file_text_write_string(saveFile, JSONList6);
        //seperate with pipe character
        file_text_write_string(saveFile, "|");
        
        ds_map_destroy(instanceMap);       
        ds_list_destroy((list1));
        ds_list_destroy((list2));
        ds_list_destroy((list3));
        ds_list_destroy((list4));
        ds_list_destroy((list5));
        
        

}

///close the file
file_text_close(saveFile);
 
Yay. The problem was later in the code. So I commented out all the other scripts so only the scr_brain_master_save() runs and the game doesn't freeze. However, I checked %localappdata%\GameMakerStudio\BatsVSBrains doesn't have a save file in it after I run the game.
 
So looking at that and I see you have done exactly what I told you not to do in the other saving script. You are trying to use json_encode with a ds_list. You can only use json_encode() with ds_map.
Code:
       JSONList = json_encode(list1);
       JSONList2 = json_encode(list2);
       JSONList3 = json_encode(list3);
       JSONList4 = json_encode(list4);
       JSONList5 = json_encode(list5);
       JSONList6 = json_encode(list6);
 
This is the alchemist table object that you click on to exit the game room and enter the alchemist lab room.

Code:
    a_choose = true; //you can choose one thing fromt he alchemist lab      
   
    scr_save_game();
    if (global.alchemist_lock == false)
    {
        room_persistent = true;
        audio_play_sound(AlchemistLabOpenSound, 20, false);
        global.RoomBeforeAlchemist = room;
        room_goto(AlchemistTableRoom);
        draw_set_colour(c_black);  
       
    }
This is the Exit Sign Object that you click on in the lab to return to the game room.

Code:
    show_debug_message("Left Pressed on Alchemist Table");
    show_debug_message("Calling function scr_skull_save()");
    scr_skull_save();



global.can_click = false;
global.can_click_timer = room_speed/2;

global.alchemist_timer = room_speed*10;
//global.clicking_timer = room_speed/15;
global.can_click  = false;
global.alchemist_lock = true;
room_goto(global.RoomBeforeAlchemist);
The bat has persistent checked.
The brain has persistent checked.
Game Level is set to persistent
Akchemist Level is not set to persistent.

I know the room persistence and object persistence are different types of persisten - i'm not quite sure which is which.
 
So looking at that and I see you have done exactly what I told you not to do in the other saving script. You are trying to use json_encode with a ds_list. You can only use json_encode() with ds_map.
Code:
       JSONList = json_encode(list1);
       JSONList2 = json_encode(list2);
       JSONList3 = json_encode(list3);
       JSONList4 = json_encode(list4);
       JSONList5 = json_encode(list5);
       JSONList6 = json_encode(list6);
@BaBiA Game Studio Yeah. That is old code. I'm sorting through it right now.
 
Top