How do I sort instance variable of a sprite?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Cute cartoon girl character with Walk, Jump, and Idle animations for 2D games.
  • Hey there, C3.

    I have a sprite (basket.id= 0,1,2) with an instance variable (.apples) that ranges in value. What I am trying to do is, when I click on a different sprite (sort), the basket with the most apples goes to spawn_point (.id=0), the second highest goes to (spawn_point.id=1) and the lowest to (spawn_point.id=2).

    I can't seem to get the coding/steps right on this. Any suggestions? I just thought of using pick highest to grab the highest value, pick lowest to move the lowest and the remaining sprite would be what's in the middle. However I'm not sure how to code that.

    Here is the most recent version I was testing:

    Thanks in advance for any help you can provide!

  • You can use "For each ordered" loop.

    For each Basket order by apples (descending)
    Spawn_point compare variable id=loopindex
    ... Basket set position to Spawn_point
    

    If there are many baskets and you want to stop the loop after the third basket you can add another condition:

    System compare value loopindex<3

  • Not sure what you do when you aren't fighting crime but that was exactly what I was looking for!!! Thank you very much.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • My identity is blown! (◣_◢)

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