Selecting the correct UID

Get help using Construct 2

Post » Wed Oct 26, 2011 11:41 am

If this has been addressed could you please send me to the relevent thread.

Take a look at the following image:



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.
B
72
S
25
G
9
Posts: 382
Reputation: 10,649

Post » Wed Oct 26, 2011 12:41 pm

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.newt2011-10-26 12:42:57
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Wed Oct 26, 2011 1:06 pm

Right, thanks for the help newt.
B
72
S
25
G
9
Posts: 382
Reputation: 10,649

Post » Wed Oct 26, 2011 1:14 pm

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!
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Thu Oct 27, 2011 11:42 pm

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
B
21
S
5
G
5
Posts: 163
Reputation: 5,028

Post » Fri Nov 11, 2011 7:05 pm

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 :)Tuiii2011-11-11 19:12:34
B
19
S
3
G
3
Posts: 56
Reputation: 2,496

Post » Sat Nov 12, 2011 10:15 am

[QUOTE=Ashley] 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![/QUOTE]

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 :DAlexmosuTSP2011-11-12 10:16:59
B
9
S
2
G
4
Posts: 19
Reputation: 2,648

Post » Sat Nov 12, 2011 2:46 pm

@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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Sat Nov 12, 2011 4:26 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Nov 12, 2011 7:21 pm

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 ?

http://www.scirra.com/forum/c2-destroy-object-problem_topic45999.html?KW=

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

saludos :D
B
9
S
2
G
4
Posts: 19
Reputation: 2,648

Next

Return to How do I....?

Who is online

Users browsing this forum: Paradox and 3 guests