jigglypuff_fun
Member
I'm attempting to track global variables over time and store them in a ds_map, where the key is the frame ID and the value is an array of the global variables' values. I'm using the
Here's my code:
Result when P1 loses 4 health on frame 293 (I'm only keeping four frames' worth of data):
Starting on frame 293, when the player went from 20 -> 16 health, the array on every frame is changed to show 16 health. But the non-array variable maintains the correct historical info on each frame.
As best I can surmise, the ds_map entries are being installed as pointers rather than the value for that variable. Is there something special with arrays that's resulting in this pointer-based result? Is there a way to correct this? I have a lot of arrays to track and it's not a realistic option to extract the data into separate variables for each one.
variable_global_get
command to do it, but the problem seems to be that the command is grabbing global pointers rather than the values themselves when the data is an array. It works fine when the data is not an array.Here's my code:
GML:
//Create Event
globalStateMap = ds_map_create(); //ds_map for tracking historical data
globalVariableNames = ["playerHealth","playerHPtest"]; //playerHealth is an array, playerHPtest is not
//End Step Event
var globalValues = [];
var frameID = global.frameCount;
global.playerHPtest = global.playerHealth[1]; //For debug, grab the value from the array
for (var k = 0; k < array_length(globalVariableNames); k++;) //Cycle through each global variable
globalValues[k] = variable_global_get(globalVariableNames[k]); //Grab the value for each variable, add it into a temp array
ds_map_add(globalStateMap, frameID, globalValues); //Add the array into the ds_map, this is the only time the ds_map is ever modified
#292 New Frame
globalStateMap = { "289": [ [ 0.0, 20.0, 20.0, 0.0, 0.0 ], 20.0 ], "290": [ [ 0.0, 20.0, 20.0, 0.0, 0.0 ], 20.0 ], "291": [ [ 0.0, 20.0, 20.0, 0.0, 0.0 ], 20.0 ], "292": [ [ 0.0, 20.0, 20.0, 0.0, 0.0 ], 20.0 ] }
#293 New Frame
globalStateMap = { "290": [ [ 0.0, 16.0, 20.0, 0.0, 0.0 ], 20.0 ], "291": [ [ 0.0, 16.0, 20.0, 0.0, 0.0 ], 20.0 ], "292": [ [ 0.0, 16.0, 20.0, 0.0, 0.0 ], 20.0 ], "293": [ [ 0.0, 16.0, 20.0, 0.0, 0.0 ], 16.0 ] }
#294 New Frame
globalStateMap = { "291": [ [ 0.0, 16.0, 20.0, 0.0, 0.0 ], 20.0 ], "292": [ [ 0.0, 16.0, 20.0, 0.0, 0.0 ], 20.0 ], "293": [ [ 0.0, 16.0, 20.0, 0.0, 0.0 ], 16.0 ], "294": [ [ 0.0, 16.0, 20.0, 0.0, 0.0 ], 16.0 ] }
Starting on frame 293, when the player went from 20 -> 16 health, the array on every frame is changed to show 16 health. But the non-array variable maintains the correct historical info on each frame.
As best I can surmise, the ds_map entries are being installed as pointers rather than the value for that variable. Is there something special with arrays that's resulting in this pointer-based result? Is there a way to correct this? I have a lot of arrays to track and it's not a realistic option to extract the data into separate variables for each one.