Expression for Pick by Object Type by UID or Pick by Nth Istance?

0 favourites
  • 2 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Is it possible to reference an object by UID or Nth Instance via expressions?

    I am doing a self collision, and found that you can choose the objects that collided by picking the nth instance. I want to compare some values of the objects, say the X-coordinate for this example, and then pick the instance based on it being higher/lower. I initially thought I could directly reference them by Object(0).X and Object(1).X, but as it turns out, this is the IID.

    Is there a way for me to similarly reference objects by the Nth Instance or UID using expressions? This will significantly trim down code, even in this example. Right now I have temporary local variables for the attributes I want to compare. I pick the 1st instance, store it to a temp variable, pick the second, and compare the variable. I understand that you can pick by Instance Comparison, but this would just mean I would have to create the temporary local variables as instance variables. This will be increasingly troublesome if I wanted to compare several attributes.

    So, is there a way, or perhaps a better approach?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This post offers the same thought I had, which was to use a local variable for storing events. As mentioned, that would probably be troublesome (more code, more variables) when comparing lots of attributes.

    construct.net/en/forum/construct-2/how-do-i-18/pick-uid-expression-59942

    I ended up using IID as a workaround, which works in my example. First I pick by Nth (0) and assign that object's IID to a local var, and do the same for the next var. Then i just use the IID to reference them in expressions and easily compare attributes

    e.g.:

    Object(IID1).X < Object(IID2).X

    Still, if anyone knows if it's possible to reference via Nth Instance via system expression or UID directly, I'd like to know how. This will remove the need for the temporary vars.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)