Sorting/Looping examples?

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

I am at the stage of my game where I need to sort 10 numbers (can be reals or integers) from lowest to highest. Is there some way of looping (I'm thinking I can just create another attribute called 'x' and add 1 to 'x' after each cycle until 'x' reaches a certain number?). Has anyone got any examples of how they have done this in GS?

Failing that, (should always ask the easier option first!) is there a function built in that will automatically sort a set of numbers?

I can sort of see how this would/could work (well the loop anyway) but would be curious on seeing how others have done it.

Thanks,
Sam

Comments

  • rebumprebump Member Posts: 1,058
    You can use an attribute to hold an integer value of the result of using the modulus operator on the game timer. May need to multiply the timer and/or add a static value to get the ranges just right for the endpoints of the loop range. Probably add a boolean attribute to keep track of when you need to end the loop or at least an additional rule line/entry in a rule block. Not near GS to test out something for you but I know I was messing with something similar about a week or so ago.
  • sparkersparker Member Posts: 47
    wow - that sounds complicated!!! If you do come across an example on screen that you can take a snap of, please do. Will no doubt help clear things in my mind!

    Thanks,
    Sam
  • ORBZORBZ Member Posts: 1,304
    no, just think of rules as loop conditions. use < and > and the min and max functions. i don't think you need a timer
  • rebumprebump Member Posts: 1,058
    Yeah, you can just use an attribute with some rule conditions and an increment (or decrement) of the attribute within the rule's behaviors.

    The timer method is a neat way to loop through some iterations at a given time tick mark and you can stop, as I stated, upon a condition being met like in the other style ORBZ mentions and I mention in my previous paragraph.

    Sorry, it sounded like you had the first method down. I was throwing out another. Didn't mean to confuse.
  • sparkersparker Member Posts: 47
    Hi guys,

    its been a long time since I first asked this, but I am back to the same point again. I have 10 attributes (reals) that I need to sort into other attributes based on how big they are. Has anyone got a bit of example code they could show me on how to do this?

    Your help greatly appreciated!

    Sam
  • sparkersparker Member Posts: 47
    I'm trying to do this basically:

    while (game.i <= 10)
    {
    if(game.racer[game.i] > game.temptime)
    {
    game.temptime = global.racer[game.i,];
    game.tempracernumber = game.i;
    }
    global.i = global.i + 1;
    }

    is this possible via a relatively simple method in GS?
    Sam
Sign In or Register to comment.