Is this a bug? Referencing by UID...

0 favourites
  • 8 posts
From the Asset Store
Act on your instances, get/set their properties and variables only thanks to their UID. No more picking trouble! Plugin
  • I came across this problem while trying to reference instanced objects variables using the object's UID. I isolated my problems down to some unexpected behavior in C2. Not sure if it's a bug, or if I'm doing something wrong when I reference the variable.

    In the example, I have some instances of my sprite, some placed ahead of time in the layout, some created at run time. The original is at 0,0. When you click on them, the text box displays information about that sprite. First it's X position, then it's X position as referenced by it's own UID. Lastly it displays the sprite's UID. When you start clicking on different instances, you see that they seemingly randomly retrieve another instance's X position instead of it's own.

    What is going on? Is it a bug, or have I done something wrong?

    dropbox.com/s/t2o3doebf1x8yyb/bugtest.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sprite(index), and Sprite.UID are two different things.

    Sprite(index) is the index for that instance as it was created from 0 to sprite.count.

    object.uid is a number assigned to any object when it is created, again from 0 to the number of objects in the game.

    Note: uid starts when you add things in the editor, and continues at runtime when you create new objects, including instances.

    What you probably want here is sprite.iid. No need for the () since you dont need to pick anything else.

  • So I could go sprite.iid.X or sprite.uid.X? to get the X position for a given instance?

  • Well you are picking the instance with the condition, so sprite.x, or self.x would be all you need. uid, and iid would be somewhat redundant.

  • In the example, it is redundant, yes. However, I'm just trying to figure out the proper syntax for use in expressions. So is that the proper syntax for referring to a particular instances variables via UID?

    Edit: Apparently not, I just tried it. How would you make that set text action work the way I intended? From within the "set text to" expression?

    Edit: It works if I use the IID in parenthesis. Cool. Still would like to know how to use the UID in expressions though.

  • Yes iid is the sprite(index), so sprite(iid) is the picked sprite.

    sprite.uid is also the picked sprite, but it has no use unless you save the uid to a variable, because you can't possibly guarantee what its uid will be at runtime.

    The general rule of thumb is if you are not creating a bunch of new instances all the time, then use iid.

    If you are then use uid, and pick via variable, or uid, as in object.uid= object.variable... do stuff.

  • You may want to check how events work.

    Contrary to a "usual" coding language, the picking (selecting) of instance is done by the conditions in the events and the actions/expressions apply to the picked instances.

    In your example, when you click on a sprite, only this sprite is picked, and so it doesn't matter to refer to it through its UID or IID.

    You might also want to check in the how do I FAQ (link in my signature) at the section "Picking/Selecting instances" there are several topics worth checking and explaining all about picking in details.

  • Thanks, guys. This little example is just to help me work out this aspect of the picking system. The project I am working on involves a lot of procedural generation and being able to reference instances of run time generated objects correctly is essential.

    I have been checking the FAQ's, manual, and forums before each post I make, but a lot of times expression syntax and other little details are left out.

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