Getting object UID when clicked on.

Get help using Construct 2

Post » Sun Apr 09, 2017 8:01 pm

The title actually says it all - I need to get the UID of the object I click on. I am creating a Tower Defense game and need to apply properties to specific instances.
B
3
Posts: 2
Reputation: 179

Post » Sun Apr 09, 2017 8:17 pm

marnussteyn wrote:...I need to get the UID of the object...need to apply properties to specific instances.


In that case you need IID (Instance ID) and not UID.
Global Var: ObjIID = 0
On left mouse click on Object | Set ObjIID to Object.IID
Image Image Image
B
29
S
11
G
27
Posts: 729
Reputation: 16,995

Post » Sun Apr 09, 2017 8:18 pm

UID works perfectly fine for identifying specific instances, and in some cases is more reliable than using IID. But the process is similar. On clicked object, set variable to object.uid.

IID: Best when dealing with order - first, second, third, next to last, last ect...
UID: Best when needing to reliably identify specific instance of any object.
Last edited by oosyrag on Sun Apr 09, 2017 8:20 pm, edited 1 time in total.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Sun Apr 09, 2017 8:19 pm

After adding mouse object;
on object clicked >> Set instance variable (value) to "object UID"
ImageImage
B
102
S
46
G
23
Posts: 773
Reputation: 22,104

Post » Sun Apr 09, 2017 9:29 pm

Solved! Thank you. :D I knew that I wanted the UID in the object's class, I just wasn't sure what to do in the event sheet to get it. I tried:

Event On mouse - On turret Clicked
Action on turret - ???

There was no option to get the ID of the turret when you are in the action menu for the turret, one needs to just select whatever variable you want and set it's value to Turret.UID, that didn't really make intuitive sense because just turret feels like it refers to the class as a whole and not the selected instance. :shock:
B
3
Posts: 2
Reputation: 179

Post » Mon Apr 10, 2017 12:20 am

https://www.scirra.com/manual/75/how-events-work

Picking - conditions pick, or "filter" instances. When your specify on object clicked, only the one that was clicked is applicable to the actions, thus allowing you to get that one UID. If you didn't narrow down to only one instance, it wouldn't work right. Therefore watch out for situations where you might click two of the same overlapping object - you would only get the UID of one of them. To fix that, you would need an additional condition to figure out which one you wanted (pick by z order to get the one on top is one solution).
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303


Return to How do I....?

Who is online

Users browsing this forum: Sparkz and 2 guests