• 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 Reliably finding same instance upon game restart

Relic

Member
I made a great little AI system that was recording player input and using this as the basis for moving the AI around. I would start recording player input when a player moved over a node instance, X, and stop recording when the player landed on a platform, Y. This would then give the AI a set of inputs that would reliably get from node X to platform Y.

It works great at first but breaks down over multiple compiles. I now realise it is because I was storing the data in a JSON that would use instance ids as a way of organising the data. These instance ids can change and so after adding a couple of new instances in the room editor, everything went pear shaped.

Looking for some inspirational ideas about reliably identifying nodes and platforms across game restarts. Ideally can be stored as a single integer so I don't have to change the system too much. All the instances are in the room editor.
 

samspade

Member
I use strings for this. They can be randomly generated or specifically designed. You could also use a custom number, but I like the readability of strings, especially for debugging purposes.

I don't think there is a way to do it with anything built into GML.
 

Relic

Member
Thanks.

I've started looking at using instance_find() as a solution. By storing the data against the "number" of the instance I care about , I hope to bypass the volatile nature of the ids. My only concern now is if instance_find() will return reliable results - even through future updates. The instances are added via the room editor. The manual explains that the instances are sorted arbitrarily - which is fine, as long as they are always sorted exactly the same way.

Quick checks confirm that between game restarts and adding new instances in other rooms, the results are reliable. Anyone with feedback on this suggestion?
 

chamaeleon

Member
How about using the creation code editor in the room editor for each instance, or the variable editor, to set instance variables to unique values that makes consistent sense regardless of instance ids?
 

FrostyCat

Redemption Seeker
If the instances never overlap exactly, combining xstart, ystart and the room's name makes for a workable form of ID. I usually recommend that for tracking persistent pickups, but it may be useful here too if the instance_find() doesn't work out.
 

Relic

Member
Both ideas have merit. The reason for not using the creation code was time saving - 10 mins coding last night has made instance_find() work with the old system. Setting unique variables manually for 20ish instances in each of the 48 rooms would work, but is tedious.

I’m keeping the x,y combo to make an auto generating reliable id as backup. Using instance_find has the advantage of being able to grab the actual id very easily but a script to iterate over all instances to grab the real id would be fine too.

Thanks!
 
Top