How do I pick multiple by UID String?

Get help using Construct 2

Post » Mon Apr 24, 2017 6:31 pm

Is it possible to pick multiple objects by UID using a string, JSON or something similar instead of using a loop?
And can I create a string of multiple UIDs, which I can use for picking? I'm trying to limit the amounts of loops I have.

I don't want to use for each - then add them to an array.
Then use for each X element of the array to pick them again, as I'm doing at the moment.

Any ideas how to go about that, and is it possible?
Follow my progress on Twitter
or in this thread Archer Devlog
B
35
S
15
G
17
Posts: 944
Reputation: 12,210

Post » Mon Apr 24, 2017 6:51 pm

I don't think so, the closest C2 has is families but of course these can't be changed at runtime. Luckly Rexrainbow to the rescue has the instance group plugin which lets you add uids to groups as you want.

http://c2rexplugins.weebly.com/rex_ginstgroup.html
B
43
S
22
G
20
Posts: 735
Reputation: 11,977

Post » Mon Apr 24, 2017 6:54 pm

Here's a one condition idea.

system: pick by comparison: sprite find(",1,3,14,6,", ","&Sprite.uid&",") =/= -1

It's a bit hard to read. Another idea is to use a boolean variable and a function:

on function "pick by uids"
--- sprite: set pick to false
------repeat function.parameterCount times
------sprite: pick by uid function.param(loopindex)
---------sprite: set pick to true

Then you could do something like this:

every tick
--- call function "pick by uids" (2, 4, 6, 10)

sprite: is pick
--- do something
B
91
S
31
G
103
Posts: 5,237
Reputation: 67,760

Post » Mon Apr 24, 2017 9:36 pm

@tunepunk

Rather than add them to an array, can you just set an instance variable? Kind of like what ROJOhound suggested, but without the intermediate step of collecting the UIDs, then setting the instance variable to pick them later... just set the Picked variable in the loop that would save the UID or add it to the array.

How often does this need to happen? Is it actually affecting performance? processors can loop through a lot of data before it becomes a problem!
B
94
S
33
G
20
Posts: 438
Reputation: 17,615

Post » Mon Apr 24, 2017 10:16 pm

R0J0hound wrote:Here's a one condition idea.

system: pick by comparison: sprite find(",1,3,14,6,", ","&Sprite.uid&",") =/= -1


I love that one condition idea. Straight & simple
ImageImage
B
102
S
46
G
22
Posts: 773
Reputation: 21,595

Post » Tue Apr 25, 2017 9:49 am

Thanks for your help guys. Some nice solutions there. I wanted to try different ways of picking in a high sprite count environment 5000+ to see what was most efficient.

Seems like dictionary and behaviors is the winner after all. In case anyone has something even more efficient.

Here is a link to capx with some of my tests:
http://tunepunk.com/share/scirra/pick-optimization.capx


@Ethan the plugin by rex was amazing. I might use this the future.
Follow my progress on Twitter
or in this thread Archer Devlog
B
35
S
15
G
17
Posts: 944
Reputation: 12,210

Post » Tue Apr 25, 2017 2:52 pm

I would think picking by instance variable would be the most efficient.
Image ImageImage
B
168
S
50
G
164
Posts: 8,231
Reputation: 105,581

Post » Tue Apr 25, 2017 3:27 pm

newt wrote:I would think picking by instance variable would be the most efficient.


I thought so too, but picking by instance you still have to check through all of the 5000 sprites for that instance variable. By loading all the previously picked in to an array or dictionary, you save your self a lot of work if you need to pick them again.

Too bad you can't add or remove objects from families in runtime. That would be awesome.

My next project is to see if I can keep a low/constant pick cost even with 10 times the amount of sprites, in this example.

Picking CPU usage scales with amount of sprites you check through every tick, so I'm trying to figure out low cost ways of doing picking in large scale layouts with high object count. Smart way of shortlisting the picking.
Follow my progress on Twitter
or in this thread Archer Devlog
B
35
S
15
G
17
Posts: 944
Reputation: 12,210

Post » Tue Apr 25, 2017 3:54 pm

You add a variable to the object.
You change that variable when it's picked the first time.
Compare instance variable, easy peasy.
Image ImageImage
B
168
S
50
G
164
Posts: 8,231
Reputation: 105,581


Return to How do I....?

Who is online

Users browsing this forum: bluesun66, plinkie and 6 guests