How do I compare instance variables on different objects

0 favourites
  • 11 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • How do i compare the same instance variable set onto multiple different objects and end up with an ordered list highest to lowest?

    I have searched everywhere and read the forums and i cant figure it out :/

  • Into the "system" conditions, you have the loop "For each (ordered)"

    It will repeats an action once for every instance of an object, and can order them according to any of their variable.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes i understand that but it only compares instances of one object.

    i want to compare multiple different objects with the same instance variable.

  • If you want to create an ordered list you don't need to compare "two" instance with each other, "For" does it and order them for you.

    So let's say you want to create a scoreboard, your code would be like:

    • For each (Object) ordered by (Score) (Descending)
    • - Put (Object) at the top of the list

    or

    • For each (Object) ordered by (Score) (Ascending)
    • - Put (Object) at the position of the list (loopindex)

    It will start putting the smallest score in the list, then the second smallest above the smallest, and will finish with the highest at the top of alls.

  • brochiefist

    you could put all the different object types in a family, and then do what Estecka said with a For Each (Ordered) on the family

  • Oh, my bad, I didn't understand the objects were of different types.

    Getting "different object" mixed up with "different instance"

  • AllanR that sounds like it will work! i'll give it a try thanks man

  • If you don't have access to the family function, you could use dictionnaries instead:

    One loop for every object type:

    For each object, create a key "Playername" with value "Score" in the dictionnary, then use a single to retrieve the keys in order.

  • How do i work the expression?

    If the variable on each instance of the object is count and i do a for ordered (family) what expression do i enter to get the instance variable count?

  • That's another problem... There are things called family instance variable, that automatically applies to all object of the family. If your variables weren't set as family from the beginning you cannot upgrade them to family.

    If you don't have a lot of code about these variables, you can delete the variable then recreate it, but otherwise I'd suggest you to use the dictionnary method right above.

  • I'll try them both and post my results. Thanks guys you are the best!

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