Pick by evaluate / for each ?

0 favourites
  • 4 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.
  • Hi.

    I would like to pick some instances by evaluate, then iterate over the returned elements them to do some specific actions (like verifying if there are other instances at fixed coordinates around them).

    What's the best way to achieve that ? Should I use a function or an array or something like that or can I manage to do this with basic conditions ?

  • wouldn't using "pick by evaluate" followed by a "for each" work? Or do you mean the issue of comparing two instances of the same type?

    For the latter, yes you could use an array. One idea would be to pick by evaluate, loop over the picked sprites and store any values you need. Then you loop over them again, checking with the values saved in the array.

    For instance you could do the following to do something for any sprite that has another 32 pixels to it's left.

    pick by evaluate

    --> set array size to (pickedCount, 3, 1)

    -- for each sprite

    ----> set array(loopindex, 0) to sprite.uid

    ----> set array(loopindex, 1) to sprite.x

    ----> set array(loopindex, 2) to sprite.y

    -- for each sprite

    ---- array: for each x

    ---- array at (array.curX, 1) = sprite.x-32

    ---- array at (array.curX, 2) = sprite.y

    ------> do something

    If instead all objects are positioned in a grid you can make it much simpler and faster.

    Start of layout

    --> array: set size to (20,15,1)

    -- for each sprite

    ----> set array(int(sprite.x/32), int(sprite.y/32)) to 1

    pick by evaluate

    for each sprite

    array at (int(sprite.x/32)-1, int(sprite.y/32) = 1

    --> do something

    You'd just need to update the array if an object is moved.

  • Thank you for your reply

    Well, I never tried but I don't know why, I assumed that pick and for each couldn't be used together. And it caused me a lot of issues these past years ! Shame on me

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Coin don't be hard on yourself mate everyone learns that way. You not the only one.

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