can i exclude a number from a random number?

guillefaceguilleface Member Posts: 1,014
edited February 2012 in Working with GS (Mac)
hi, i have a actor that when collides with trigger it changes self. att. direction to random(1,4)
when self. direction =1 move 0 degrees related to scene.
when self. direction =2 move 180 degrees related to scene.
when self. direction =3 move 90 degrees related to scene.
when self. direction =4 move 270 degrees related to scene. but i would like to exclude the attribute from the direction is coming. say if direction is 0, then to choose a random from 2,3,4
if direction is 180 to chose random from 1,3,4
pretty much i don't want to go back from the direction is coming. thanks in advance

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    you could make a attribute called lastDirection

    so change self.direction to random(1,4)
    then in the same rule change lastDirection to self direction

    then another rule if lastDirection = self.direction
    change self.direction to random(1,4)

    what that will do is as soon as the random number is the same as the last number it pulled, itll change it again and keep changing till its not the same

    There might be a better way to do it, but that should work

    cheers
  • allornothingallornothing Member, PRO Posts: 126
    Could that not all be the one rule?

    i.e.
    if lastDirection = self.direction
    change self.direction to random(1,4)
    otherwise:
    change.self.direction to random (1,4)
    change lastDirection to self.direction

    or is my logic wrong? Trying to tune my brain into this kind of thing so apologies if incorrect.
  • ozboybrianozboybrian PRO Posts: 2,102
    Just set up a rule. If the number you don't want is 8.

    Rule - If att = 8 Random Number.
    So it'll keep randomising till it gets a different one.

    Easy :D
  • 3xL3xL Member Posts: 676
    Oz boy beat me to it

    I was also gonna suggest something like

    If attribute is not 8
    Then blah blah blah

    But the other way seems better
  • guillefaceguilleface Member Posts: 1,014
    hey guys thanks alot but i dont know is not working maybe because i have to change the attribute every .20 seconds when collide with trigger, i thought about a game similar to pacman so sometimes say if actor is traveling up when collides with trigger the only option is left or right, so say it choose to go up but since is hitting a wall it wont move so thats why i add every .20 so if gets stuck moving into a wall,since is still colliding with triiger it will random pick another position , at this moment i want to chose anything except going back from where it came,
  • aarioaario Member, PRO Posts: 256
    edited February 2012
    Its pretty simple really all you have to do is make a table.. so ill walk you through it

    column 1 <2,3,4>
    column 2 <1,3,4>
    column 3 <1,2,4>
    column 4 <1,2,3>

    Type everything in as shown then in your rule use the following..

    when self.Direction=1 change self.Att to tableCellValue(Table1,random(1,3),column 1)
    when self.Direction=2 change self.Att to tableCellValue(Table1,random(1,3),column 2)
    when self.Direction=3 change self.Att to tableCellValue(Table1,random(1,3),column 3)
    when self.Direction=4 change self.Att to tableCellValue(Table1,random(1,3),column 4)

    I havent tested it but that should work for you!

    Goodluck,
    Aaron :)
  • guillefaceguilleface Member Posts: 1,014
    this looks good , i will try this tomorrow thank you.
Sign In or Register to comment.