How do I pick multiple by UID String?

0 favourites
  • 9 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • 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?

  • 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

  • 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

  • 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!

  • 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

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I would think picking by instance variable would be the most efficient.

  • 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.

  • You add a variable to the object.

    You change that variable when it's picked the first time.

    Compare instance variable, easy peasy.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)