Loading...
Logo
Processing Forum
I don't really know how to search for this, but I have a feeling it has been answered already. I want save all the data for one object so that I can make changes to the object and then revert back to it later. Currently I have something like this, although not exactly:

void updateObject(){
pObject=object;
object.update();
}
void revertObject{
object=pObject;
}

But that doesn't work, presumably because I just don't really understand computer memory.
Also, the object in question has a lot of different variables and types of variables associated with it, if that has any impact on a solution.

Replies(1)

In your code example, pObject just points to the same object than object. So if you update the object pointed by one, the other see the same changes.
You have to clone the object, to make a copy of it, instead.
See for example http://stackoverflow.com/questions/869033/how-do-i-copy-an-object-in-java or http://www.javapractices.com/topic/TopicAction.do?Id=71 for good practices on this.