Selecting the correct UID

0 favourites
From the Asset Store
Act on your instances, get/set their properties and variables only thanks to their UID. No more picking trouble! Plugin
  • If this has been addressed could you please send me to the relevent thread. <img src="smileys/smiley1.gif" border="0" align="middle" />

    Take a look at the following image:

    <img src="http://img803.imageshack.us/img803/3523/clipboard01t.png" border="0" />

    Is there anywhere in the Layout that will tell me the UID of the selected image? I'm sure I've just missed it so if anyone can point it out I'd be grateful. <img src="smileys/smiley2.gif" border="0" align="middle" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Actually I think the reason its not there, is because uid's aren't assigned until runtime.

    Also there's no good way to guess the uid, because the naming method is shared between all objects.

    What you can do is create the objects and place the uid into a instance variable, and then pick by that.

    Or, you can pick by the sprites index "pick "nth"". This is unique to named object types, so all instances of the same object are easier to pick. Just remember the first is 0, second 1, etc. Then in expressions you can use sprite(index) to reference a specific instance, sprite(0).x would be the first created sprites x.

  • Right, thanks for the help newt. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Newt is right, it's deliberate that you can't see UIDs, because they're unreliable. If you see an object has a UID of 5, then you insert another object, the previous object's UID could change to 6. Then your events are broken. So it's best not to show them!

  • Or, you can pick by the sprites index "pick "nth"". This is unique to named object types, so all instances of the same object are easier to pick

    exactly what I want

    A valuable advice for me Thanks <img src="smileys/smiley20.gif" border="0" align="middle" />

  • Can someone explain me this better?

    I'm having problems with it and cant manage to make it work.

    I didn't understand what you said here:

    Or, you can pick by the sprites index "pick "nth"". This is unique to named object types, so all instances of the same object are easier to pick

    If possible could you show me an example?

    What I'm trying to do is hit the button "1" of the keyboard to activate the object with 50 opacity. It will follow the mouse cursor untill I click the mouse left button. And than if I hit the button "1" again I want the new object to follow the mouse cursor. (My attempts are leading to all objects created follow the mouse cursor or the wrong object to follow it)

    --EDIT--

    Oooh nevermind.. I just got it.

    I set pick "nth" to pick the object count + 1 and its working exactly as I wanted :D

    Thanks anyway :)

  • Newt is right, it's deliberate that you can't see UIDs, because they're unreliable. If you see an object has a UID of 5, then you insert another object, the previous object's UID could change to 6. Then your events are broken. So it's best not to show them!

    WOW...just a second there, you mean if an object is spawned and gets UID 3, and then another instance of that object, already spawned, is destroyed, the obect's UID changes from 3 to...2 ?

    Or how does it change? And why ?

    saludos :D

  • AlexmosuTSP - UIDs only change in the editor. So if you hard-code an event that says "pick object with UID 5", and do some stuff in the editor, that event might later refer to a different object.

    UIDs however are always unique to an object at runtime. So if you retrieve an object's UID and store it in an instance variable, for example, it will always refer to that object.

  • So basically if you have an object that will have multiple instances, and you aren't destroying those instances all the time, you might want to use uid for picking.

    But the best way to use that method is to do it at runtime, and store the objects uid on creation.

    Otherwise, if you want multiple instances, that may be destroyed at random times, use pick "nth", or sprite().

    Not that pick nth cant be used for objects that wont be destroyed.

    And keep in mind its much easier to pick chains of sprites using this method as well.

  • oh I understand, so at runtime, the UIDs don't change, I mean once the game starts.

    The example of destroying a rocket's exhaust sprite, checking if an instance variable is the same as the Rocket's uid, to make sure the exhaust destroyed is only the one belonging to that rocket, is supposed to work then, no ?

    scirra.com/forum/c2-destroy-object-problem_topic45999.html

    Is that a good implementation, in my answer ? Or will it fail ?

    saludos :D

  • Is there a way to pick an object at point X, Y?

    I'm thinking in creating an invisible object and then using the "Is overlapping another object" test.

    But is there a better way? I want to loop over blocks and check if there's another block under it.

  • AlexmosuTSP - UIDs only change in the editor. So if you hard-code an event that says "pick object with UID 5", and do some stuff in the editor, that event might later refer to a different object.

    UIDs however are always unique to an object at runtime. So if you retrieve an object's UID and store it in an instance variable, for example, it will always refer to that object.

    Can you give me an example of this, please?

    My situation is where I'm using instances of a small block sprite to represent a health meter. Every time my character is damaged, an instance of the sprite will be destroyed. How do I initially call for the sprite's UID and store it to an instance variable? Am I to assume you mean an instance variable OF the sprite object, itself?

  • Rhindon:

    The point is you have to save the UID by using events, so that they are saved AFTER the game has started, because the UID values are set when the game is run. You can't set a variable to a UID in the C2 editor, because the UID values are created afterwards, when you preview.

    At any point you find fit (in the event sheet), you can use BodyPart.UID to get the UID of an object and save it to an instance variable you've created in the MainBody object.

  • I had a similar question about UID and instances. Store the values in a dictionary. I created a demo of what I was working on to solve this.. it may help out - Demo

  • Thank you for the help! :) I got it worked out.

    For my situation, I called on the instance count of the object and told it to -1 in order to refer to the actual ID #.

    So, if I have five instances (IID #s 0, 1, 2, 3, 4) and want to destroy the last created/existing instance, then -1 gets me to that correct # and destroy it. So far, it's working.

    The instructions I gave go like this:

    ->PlayerBox | On collision with Enemy

    -->(sub-event) System | Pick Sprite instance (Sprite.PickedCount-1) => Sprite Destroy

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