Object persistence - Resets coordinates upon setting persistent again

F

FactorX12

Guest
Hi,

So I have a game I'm making, and there are parts that set the persistence of objects to false, but when I turn it back to true, the x and y of the object reset. Let's say there's an object, it's starting point upon entering the room is (10, 10) and I move it in-game to (30, 30). Then, I set the persistence to false, switch room, and set it back to true, which sets the coordinates of the object back to (10,10). This is frustrating, because this is exactly what I don't need to happen. Any help?
 

samspade

Member
Hi,

So I have a game I'm making, and there are parts that set the persistence of objects to false, but when I turn it back to true, the x and y of the object reset. Let's say there's an object, it's starting point upon entering the room is (10, 10) and I move it in-game to (30, 30). Then, I set the persistence to false, switch room, and set it back to true, which sets the coordinates of the object back to (10,10). This is frustrating, because this is exactly what I don't need to happen. Any help?
I'm not entirely sure I understand, but it sounds like that is what you are telling it to do. Or put it this way. If you have turn off an object's persistence and then switch rooms, that object is gone. Keeping an object past room changes is essentially the whole point of persistence. So how does that object get created again? Not by some magical save state, but by where it is located in room editor or code that places it originally - meaning it will go to that point. It doesn't set the coordinates of the object back to 10, 10 the object doesn't exist. It creates the object at 10, 10 (where it is supposed to).

If you don't want this to happen, you will have to save those variables - likely in some sort of global variables - and then when the object is recreated, set its x and y to those saved variables.
 

NightFrost

Member
Any help?
By what I gather from your explanation, you might be misunderstanding persistence a little. Under normal circumstances, when you exit a room all instances in it get destroyed. Persistence is the idea that they do not, and get transferred to the room you move into. Consequently, when you turn off persistence and exit a room, the formerly persistent instance will get destroyed. It reappears when you enter its original room simply because upon room creation, all instances placed into the room editor get created automatically. The fact that an older instance created from the same object was persistent for a small while has no relevance to this; the new one is its own instance, the old one has been destroyed and all information regarding it has been lost.
 

samspade

Member
By what I gather from your explanation, you might be misunderstanding persistence a little. Under normal circumstances, when you exit a room all instances in it get destroyed. Persistence is the idea that they do not, and get transferred to the room you move into. Consequently, when you turn off persistence and exit a room, the formerly persistent instance will get destroyed. It reappears when you enter its original room simply because upon room creation, all instances placed into the room editor get created automatically. The fact that an older instance created from the same object was persistent for a small while has no relevance to this; the new one is its own instance, the old one has been destroyed and all information regarding it has been lost.
This is a better explanation than mine.
 
Top