Hi,
I'm still having issues with JSON_Stringify. I have a function based on Shaun Spaldings video called "GameMaker studio 2 - Best Saving and Loading Tutorial (2.3.1+)". (It's an awesome video)
The function is pretty straight forward:
1. An array is created and then the function gets each entity with the parent of PSAveMe.
2. Each entity is pushed to an array, and then after all entities are added json_stringify is used and then the file is written via a buffer.
This was working perfectly, but all of a sudden it stopped working and the variable getting the stringify returns a "null", nothing more.
I've spent a few hours debugging and tracking each variable to see if anything is undefined. I've also compared the code I'm using to the code in the tutorial, it all looks the same.
I've also taken the code that is pushed to an array and tested stringify on this, that works fine. It also works if I convert the array to a string, but not if I just pass the array into the json_stringify function.
I am running Gamemaker Studio 2 IDE version 2.3.7.603 Steam, Current Runtime 2.3.7.474.
Here is the code below, hopefully someone will spot something I've missed (After staring at a screen things often get overlooked after I am driven absolutely bats!)
Has anybody had this issue?
I'm still having issues with JSON_Stringify. I have a function based on Shaun Spaldings video called "GameMaker studio 2 - Best Saving and Loading Tutorial (2.3.1+)". (It's an awesome video)
The function is pretty straight forward:
1. An array is created and then the function gets each entity with the parent of PSAveMe.
2. Each entity is pushed to an array, and then after all entities are added json_stringify is used and then the file is written via a buffer.
This was working perfectly, but all of a sudden it stopped working and the variable getting the stringify returns a "null", nothing more.
I've spent a few hours debugging and tracking each variable to see if anything is undefined. I've also compared the code I'm using to the code in the tutorial, it all looks the same.
I've also taken the code that is pushed to an array and tested stringify on this, that works fine. It also works if I convert the array to a string, but not if I just pass the array into the json_stringify function.
I am running Gamemaker Studio 2 IDE version 2.3.7.603 Steam, Current Runtime 2.3.7.474.
Here is the code below, hopefully someone will spot something I've missed (After staring at a screen things often get overlooked after I am driven absolutely bats!)
GML:
function saveLevel() {
// Set local variables
var _levData = array_create(0);
// This is only here to show the same data in a string being converted to JSON
var _teststringify = [ { x : 0, y : 252, image_index : 0.25, obj : "obj_ladder" } ];
var _teststring = json_stringify(_teststringify);
show_debug_message(_teststring);
// For every instance, create a struct and add it to the array
with (pSaveMe)
{
var _saveEntity =
{
obj : object_get_name(object_index),
y : y,
x : x,
image_index: image_index,
}
array_push(_levData,_saveEntity);
}
// turn the array into a JSON string and save it via a buffer
var _string = json_stringify(_levData); // <--- This is where it all goes to pot
var _buffer = buffer_create(string_byte_length(_string)+1, buffer_fixed, 1);
buffer_write(_buffer, buffer_string, _string);
buffer_save(_buffer, "levelsave.json");
buffer_delete(_buffer);
}
Last edited: