1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GML select an instance with its ID ?

Discussion in 'Programming' started by hazonsassoun, Dec 31, 2018.

Tags:
  1. hazonsassoun

    hazonsassoun Member

    Joined:
    Oct 20, 2016
    Posts:
    13
    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.
     
  2. Ratsha

    Ratsha Member

    Joined:
    Jun 22, 2016
    Posts:
    59
    Every instance already have an ID assigned by Game Maker, and you can use the keyword with for ids yes.
     
  3. hazonsassoun

    hazonsassoun Member

    Joined:
    Oct 20, 2016
    Posts:
    13
  4. Ratsha

    Ratsha Member

    Joined:
    Jun 22, 2016
    Posts:
    59
    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
       }
    }
     
  5. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,217
    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.
     
    Ratsha likes this.
  6. Ratsha

    Ratsha Member

    Joined:
    Jun 22, 2016
    Posts:
    59
    Ah thanks, didn't know that. That just makes the code cleaner.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice