Skip to main content

The "instance_find_var" Function


instance_find_var(var, n);
varstringThe variable name to search for, as a string
nintegerThe ordinal instance number to return, if multiple results are found


Searches existing instances for a particular variable and returns the ID of the containing instance, or keyword noone if not found.

If multiple matching instances exist, you can specify which number to return with the n argument, where the first instance is 0. If the input number is greater than the number of matching instances, the last result will be returned.


GameMaker instance order can vary based on many factors, so when multiple instances exist, this script may not always return the same ID each time!


var inst = instance_find_var("my_var", 0);
if (inst == noone) {