• 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!

GameMaker How can I delete instances that were taken in a previous playthrough?

Z

zpinn

Guest
I have already have a system that saves strings in a text file and loads from that file at game startup, but as far as I understand, instance IDs are set once the game compiles. So their IDs will be different each time the game starts up?

How can I refer to instances based on an ID that was saved the last time the game ran?
 

Simon Gust

Member
You cant. You have to save all the information you need to emulate a new instance that was just like the one before.
What object it is, where it was, in what state it was in etc.
 

NightFrost

Member
Instance IDs are handed out in creation order, without regarding the object. I believe GM never deviates from the straightforward N++ incremental numbering. This means if you recreate by instance id, if you make even single mistake everything afterward will be out of whack. If there are destroyed instances, you'd need to consider skipping over id values as well. This would be a nightmare to debug. The saner alternative, as given above, is to save all the relevant data from the instance and then use it to recreate them by first doing instance_create and then feeding it the values.

(One should never write code that assumes specific instance ids are the same from one session to another. Your player might be 100000. It also might not.)
 

FrostyCat

Redemption Seeker
Instead of recording instance IDs, build your own IDs from properties that stay consistent between sessions. A quick baseline scheme is the room name plus the starting x and y coordinates (i.e. room_get_name(room) + "," + string(xstart) + "," + string(ystart)).
 
Top