How do I compare and sort different items?

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.
  • Say I have 10 characters (this is just a make belief example I'm not actually doing this in my game) with different heights, and I want the game to sort them in accordance with their height, and not just that but also have the ability to add or remove characters from the list.

    Ex:

    Dave: 185cm

    Bob: 192 cm

    Yale: 179 cm

    How would I have the game take that list of names and reorganize it to have the tallest people appear on top? And what if I wanted to get even more specific and select characters within a specific height range?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do you an object associated with these characters, say, are they sprite instances? Then the easiest way is to add instance variables CharName and CharHeight to the sprite. You will be able to pick a character with highest/lowest height, or iterate through them ordered by height.

    If characters exist only as data, then it's a completely different approach. For example, if there is an array of characters, you can sort it by height and get the first/last record from the array.

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