Get IID from UID?

Get help using Construct 2

Post » Sun May 29, 2016 9:59 pm

Is this possible?

var = Enemy(Enemy.UID.GETIID()).X

How can i capture the IID using a UID?
B
4
Posts: 9
Reputation: 214

Post » Sun May 29, 2016 10:35 pm

Use a function.

var = function.call("getiid", enemy.uid)

on function "getiid"
pick enemy by uid function.param(0)
--- function: set return value to enemy.iid
B
94
S
33
G
118
Posts: 5,394
Reputation: 75,849

Post » Sun May 29, 2016 11:24 pm

It works, thanks

Now i have a different problem, all my family members (Enemy) contain the same IID

I will search about it
B
4
Posts: 9
Reputation: 214

Post » Sun May 29, 2016 11:46 pm

The function won't work, as picking a single object will always return an index of zero. Maybe expand on what you are really doing.

The UID is unique, the IID is just an index for the picked objects.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198

Post » Mon May 30, 2016 12:57 am

@blackhornet
The iid isn't related to picking, it's the instance number of the object type. I've utilized this to access values in unpicked objects. Off the top of my head, one use could be to compare two random instances of the same type.

global number other=0

pick random sprite instance
--- set other to sprite.iid

pick random sprite instance
sprite x < sprite(other).x
--- destroy sprite


@liev04
I didn't look into it previously but after a quick test iids are an instance number of a object type, not a family. So the object.iid will give the instance number of that type and not instance number in that family. However, the family(3).x style expression will give you the forth (counting from 0) instance in the family.

A brute force solution could be to change the function to:

on function "getiid"
for each family
system: compare function.param(0)=family.uid
--- function: set return value to loopindex
--- stop loop

Another way could be to give the family an instance variable that you set to their index number when you create it. You'll also need to update it when an instance is destroyed. There's probably other ways too.
B
94
S
33
G
118
Posts: 5,394
Reputation: 75,849

Post » Mon May 30, 2016 12:53 pm

What would one do with the knowledge of the IDD (the index of a certain object in the list of picked objects) when all objects are picked ?

Certainly when calling a funtion. I suppose the function gets called from a situation where there is certain picked object list. And one wants the IID of that object in that specific list. There is not one correlation between the picked list (and its indexes) in the event with the function call and the picked list in the on function (all and theire indexes when picked all).

Just pick the instances (or objects with a famely) you want to pick. (make a picklist)
Run trought them with a for loop
Pick the instance by its IID (pick nth) = loopcounter
This instance has an UID, but that is not importand now at this moment yet
Set an instance variable to the IDD or to the loopindex

Now you can pick any instance with an UID, its IID is in the instance variable.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: max2612 and 4 guests