How do I compare instance variables on different objects

Get help using Construct 2

Post » Wed Jun 29, 2016 1:56 am

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 :/
B
3
Posts: 8
Reputation: 191

Post » Wed Jun 29, 2016 2:05 am

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.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Wed Jun 29, 2016 2:08 am

Yes i understand that but it only compares instances of one object.

i want to compare multiple different objects with the same instance variable.
B
3
Posts: 8
Reputation: 191

Post » Wed Jun 29, 2016 2:22 am

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.
Last edited by Estecka on Wed Jun 29, 2016 2:24 am, edited 1 time in total.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Wed Jun 29, 2016 2:23 am

@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
B
94
S
33
G
20
Posts: 438
Reputation: 17,615

Post » Wed Jun 29, 2016 2:25 am

Oh, my bad, I didn't understand the objects were of different types.
Getting "different object" mixed up with "different instance"
Last edited by Estecka on Wed Jun 29, 2016 2:40 am, edited 3 times in total.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Wed Jun 29, 2016 2:27 am

AllanR that sounds like it will work! i'll give it a try thanks man
B
3
Posts: 8
Reputation: 191

Post » Wed Jun 29, 2016 2:30 am

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.
Last edited by Estecka on Wed Jun 29, 2016 2:38 am, edited 1 time in total.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Post » Wed Jun 29, 2016 2:32 am

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?
B
3
Posts: 8
Reputation: 191

Post » Wed Jun 29, 2016 2:37 am

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.
B
7
S
3
G
3
Posts: 56
Reputation: 2,240

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests