Selecting the correct UID

Get help using Construct 2

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

Post » Thu Nov 24, 2011 7:20 pm

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.
B
6
S
1
G
5
Posts: 1
Reputation: 2,157

Post » Sat Jan 26, 2013 6:34 am

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

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?
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
113
S
20
G
8
Posts: 741
Reputation: 13,661

Post » Sat Jan 26, 2013 5:38 pm

@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.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Sat Jan 26, 2013 5:53 pm

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
Image Image Image
B
60
S
19
G
5
Posts: 325
Reputation: 7,369

Post » Sun Jan 27, 2013 9:25 am

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 DestroyRhindon2013-01-27 09:26:30
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
113
S
20
G
8
Posts: 741
Reputation: 13,661

Post » Sun Jan 27, 2013 10:21 am

@Rhindon

Here are couple of different ways to make healthbars.

Hope it's some help to you, includes picking stuff like you did too :)vee412013-01-27 10:22:18
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Previous

Return to How do I....?

Who is online

Users browsing this forum: Callan S, gamecorpstudio, Kagubro and 15 guests