• 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 Restoring States - Taking an object back in time

Hey all! I'd like to figure out the best way to restore an object to its exact previous state from an earlier frame, including all variables that it's managing, which would effectively take the object back in time. Given some of my objects have 100+ variables, and on top of that I have dozens of objects, I'd rather not manually log each variable every frame and perform a restoration that way. Unless there's an automated way of logging those variables?

I was wondering about creating an instance_copy() every frame to create a stamp of that object, and then deactivating it. Then if I wanted to go back in time, I would activate the appropriate frame's object and delete the original object, but this brings some pain as well - such as the id changing, plus I'm not sure if that would bog down the game at all from a resourcing perspective.

What would be the best way to do this in GameMaker? I've been coding in GML for a few years now, but I'm just not sure how to tackle this one.
 
Okay, I've been playing with this function and it looks like it will work in tandem with variable_instance_get. One limitation seems to be that it doesn't capture the native variables like x, y, image_index, etc. Is there a native GM function that captures those, or otherwise a complete list somewhere of all the variables so I can write my own function?
 

sylvain_l

Member
deactivated clone could work depend how much time you want to keep

if you only keep the last 10 sec and your game run at 60FPS you'll end up with only 600 deactivated copies of each of your 12 objects. Not a problem.

if you want to keep an hour of game length, you'll have to start to think of how much ram you'll use. ('cause of the 216'000 deactivated clones :p)
 

DaveInDev

Member
yes finally instance_copy and deactivation is finally not a bad solution. Depends if other objects refers to this object, because when you'll replace it by its clone, they will lose the link.
 
Hey all, I was able to make this work with the variable commands! Thanks much for all the help. I'll leave my code here to help anyone else who is looking to do something similar.

GML:
var frameID = global.frameCount;
var variableNames = variable_instance_get_names(id);
var variableValues = [];

//Grab all local variables and write them to the ds_map
for (var i = 0; i < array_length(variableNames); i++;)
    variableValues[i] = variable_instance_get(id,variableNames[i]);
ds_map_add(localStateMap, frameID, variableValues);

//Clean up map, only keep X frames' worth of data
var framesToKeep = 5;
for (var j = 0; j < ds_map_size(localStateMap); j++;)
    ds_map_delete(localStateMap, frameID - framesToKeep - j);
I'm now having a strange issue with using the related global commands to grab values there, at least when the values are an array. I made a new post about it here, feel free to take a look if you have any thoughts: https://forum.yoyogames.com/index.php?threads/tracking-global-arrays-pointers.82742/
 
Top