Is my logic correct? (sorting values)

sparkersparker Member Posts: 47
edited November -1 in Working with GS (Mac)
Hi all,

wondering if I can get a second set of eyes (or a few more...) to take a look at my logic and tell me if it is right. Basically, what I am trying to do is to take a collection of numbers, and sort them from largest to smallest There are ten numbers that will be stored into attributes (called time10, time9 etc. all the way to time1 - time 1 being the smallest.

Basically to do this I have done the following:

time10 = max(max(max(max( game.r1b , game.r2b ),max( game.r3b , game.r4b )),max(max( game.r5b , game.r6b ),max( game.r7b , game.r8b ))),max( game.r9b , game.r10b ))

Then I test each one to find which time was the largest:
if time10 = game.r1b
game.r1b = game.r1b - 100
other wise
if time10 = game.r2b
game.r2b = game.r2b - 100 (etc.)

(the times are between about 6.00 and 15.00, so taking 100 off them certainly makes them smaller than the rest)

Then with the largest number found, assigned to time10 and then 100 taken off its original provider, the process goes through again:

time9 = max(max(max(max( game.r1b , game.r2b ),max( game.r3b , game.r4b )),max(max( game.r5b , game.r6b ),max( game.r7b , game.r8b ))),max( game.r9b , game.r10b ))

Can anyone see any problems with this method? I have a problem whereby it doesn't seem to work 100% of the time, normally an issue with assigning the same value to two "time" attributes when they should be different times. This seems to only happen with time2 and time3 or sometimes time3 and time4.

The only thing I can think (after spending hours looking through it) is that there is some sort of issue with my logic. If anyone could take a look and let me know - it'd be greatly appreciated!

Regards,
Sam

Comments

  • sparkersparker Member Posts: 47
    Anyone willing to take a look over it?
    Sam
  • sparkersparker Member Posts: 47
    Or failing anyone looking over it, could someone suggest a better alternative?

    Sam
  • sparkersparker Member Posts: 47
    Anyone?
  • sparkersparker Member Posts: 47
    I'd be very very very interested in your thoughts, this has drove me crazy! I even tried to seperate each of the Max(1, 2) statements into separate equations, but got exactly the same answer.....

    Sam
  • sparkersparker Member Posts: 47
    bump?
  • bluebyu25bluebyu25 Member Posts: 500
    Doing any kind of sorting (i.e. bubble,selection...) is going to be a pain in GS. Until we have array support, you are just going to have to tinker...a lot.
  • old_kipperold_kipper Member Posts: 1,420
    This is a real pain to do. You need to hold the values in attributes, have a second set of label attributes that seek sequentially an order in the stack and attach to a highest or lowest non selected number. I never got it working well and even considered a mechanical approach; scaling a y position in the scene for invisible actors for each number positioned based on their value and then having a sweeping bar that clocked which one it hit in order and numbering them... Didn't actually try it.

    kipper
  • sparkersparker Member Posts: 47
    Hi all,

    thanks for the replies. I know that it would be easier with an array and some easier looping, however I am concerned that even this wouldn't fix it. I mean, I don't understand why my example doesn't work (well does, about 85% of the time?)

    Does GS choose when to accept a MAX(val1, val2) command? Surely it doesn't just get over it half way and move onto the next command? Hopefully not!

    Sam
  • sparkersparker Member Posts: 47
    **Update**

    I am wondering if its an issue with the max() statement itself. Even after breaking it down into individual max() statements, it still does exactly the same thing. I am thinking I might try the old

    If a > b
    then temp1 = a
    a = a -100
    otherwise temp1 = b
    b= b -100

    If c > d
    then temp1 = c
    c = c -100
    otherwise temp1 = d
    d = d -100

    etc.

    Any thoughts?

    Sam
Sign In or Register to comment.