GML select an instance with its ID ?

H

hazonsassoun

Guest
Hello
Imagine that I have a variable containing an ID (integer) like : myid = other.id;
But that's not really the question, I would like to know if there was any way to do something like this:

with(myid) { ... }

instead of

with(other) { ... }

Is it possible ? Is it possible to use the "with" word by using an id ?

Thanks.
 
R

Ratsha

Guest
Every instance already have an ID assigned by Game Maker, and you can use the keyword with for ids yes.
 
R

Ratsha

Guest
Well, it depends on how you're obtaining the id. An example for collision line would be:
Code:
var myid = collision_line(x1, y1, x2, y2, obj, false, true);
if (myid != noone)
{
   with(myid)
   {
      // Code for myid
   }
}
 

Simon Gust

Member
Well, it depends on how you're obtaining the id. An example for collision line would be:
Code:
var myid = collision_line(x1, y1, x2, y2, obj, false, true);
if (myid != noone)
{
   with(myid)
   {
      // Code for myid
   }
}
Small remark, when using with, an id check to noone is not necessary, with (noone) does not run it's loop, nor cause an error.
 
Top