How do I pick several UID instances at the same time

Get help using Construct 2

Post » Fri Apr 25, 2014 4:56 pm

Is possible to use a event to pick several instances at the same time using the UID of each one and then compare frame number and apply an action after?

Like this?

Code: Select all
Event:
Pick instance with UID 0
Pick instance with UID 1
Pick instance with UID 2
Pick instance with UID 3

Subevent:                                 
Animation frame = 3

Action:
Set variable to 1


Thanks
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Fri Apr 25, 2014 6:23 pm

You could do this:
Code: Select all
Event:
Repeat 4 times
Pick instance with UID int(tokenat("0,1,2,3", loopindex, ","))

Subevent:                                 
Animation frame = 3

Action:
Set variable to 1
B
94
S
33
G
113
Posts: 5,356
Reputation: 73,273

Post » Fri Apr 25, 2014 6:52 pm

Simpler pick:
Pick instance by evaluating instance.UID >=0 && instance.UID <=3
ImageImageImage
B
71
S
22
G
248
Posts: 3,756
Reputation: 138,058

Post » Fri Apr 25, 2014 7:09 pm

....or even

Pick instance by evaluating instance.IID <= 3

I think you might be confusing UID and IID. The UID for each different instance or object is unique, so unless your objects are the first 4 that were created on any layout then this will return nil. There are no IIDs (or UIDs) <0, so you don't need to check for > 0. If you use IID this way you will pick (in this example) the first 4 of your instances that were created. I haven't tested this so I could be mistaken....
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,245
Reputation: 46,464

Post » Fri Apr 25, 2014 7:43 pm

@R0j0hound: Thanks for suggesting this solution. I used "tokenat" a few times. I didn't know how to use it in this situation. Many thanks. One doubt: if the UIDs are not in sequence, can I continue to use the "tokenat"?

@blackhornet: Thank you for this simple solution. But how can I do if the UIDs are not in sequence. Maybe something like this:

Code: Select all
Pick instance by evaluating instance.UID=0 && instance.UID =3 && instance.UID =5 && instance.UID =9

@Colludium: I understood your explanation and I intend to test it, but before I need to know how can I do if the UIDs are not in sequence. Thank you.
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Fri Apr 25, 2014 8:17 pm

That's the problem with absolute examples; you get absolute solutions.

You'd be better off flagging the instance you care about in some other manner (instance variable) so you can pick them with a simpler test, rather than with a list of UIDs.
ImageImageImage
B
71
S
22
G
248
Posts: 3,756
Reputation: 138,058

Post » Fri Apr 25, 2014 8:26 pm

I'm not sure exactly what you want to test for so I'll try and help as best I can. Each object is assigned a UID and an IID when it is created, whether that's in the editor (seen when the layout is loaded, but you can check in the properties bar) or whenever you create an object. I don't know if UIDs are reused after an object is destroyed but I suspect not. IIDs are reused, so if you destroy the first 5 objects that were created out of 8 total, the last 3 will be renumbered IID from 5-7 to 0-2. Here's the manual info.
A big fan of JavaScript.
B
76
S
20
G
74
Posts: 2,245
Reputation: 46,464

Post » Sat Apr 26, 2014 12:32 pm

blackhornet wrote:That's the problem with absolute examples; you get absolute solutions.

You'd be better off flagging the instance you care about in some other manner (instance variable) so you can pick them with a simpler test, rather than with a list of UIDs.



@blackhornet: Instance variables is an alternative but I'm using lots of istances and I need to check just 4~10. The problem is that not always the same instances. Do you know if the example that I wrote before works?

Code: Select all
Pick instance by evaluating instance.UID=0 && instance.UID =3 && instance.UID =5 && instance.UID =9
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Sat Apr 26, 2014 12:35 pm

Colludium wrote:I'm not sure exactly what you want to test for so I'll try and help as best I can. Each object is assigned a UID and an IID when it is created, whether that's in the editor (seen when the layout is loaded, but you can check in the properties bar) or whenever you create an object. I don't know if UIDs are reused after an object is destroyed but I suspect not. IIDs are reused, so if you destroy the first 5 objects that were created out of 8 total, the last 3 will be renumbered IID from 5-7 to 0-2. Here's the manual info.


@Colludium: I just need to check the frame number of some specific instances
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Sat Apr 26, 2014 1:06 pm

Yes, that will work. I'm just suggesting that you do something like adding an instance variable, lets say 'Special', then you set the instances you care about to '1', and do a Pick instance.Special=1. This is a cleaner solution, and more versatile than hardcoding UIDs. It's your call.
ImageImageImage
B
71
S
22
G
248
Posts: 3,756
Reputation: 138,058

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 56 guests