Random Doesn't Work

11clock11clock Member Posts: 450
edited November -1 in Working with GS (Mac)
Until 9.5, expression 'random(min,max)' worked well for me. Now it doesn't seem to work at all. I had a timer that said every random(1,3) seconds it will do something, but it will always do it every 1 second. I then made a variable called self.random that starts at 3 and changes to a number from 1 to 3 every time the timer goes off. The timer goes off every self.random seconds. However, this time it will not change the variable and the timer will only go off every 3 seconds.

Is there a way to fix this?

Comments

  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Timers havenever worked like that with random. They always pick a number the first time they run and then keep that number

    You have to set your self attribute and then a separate timer that says every 0 seconds change attribute to random(1,3) then use the attribute for your other timer duration be sure to check run to completion
  • 11clock11clock Member Posts: 450
    tenrdrmer said:
    Timers havenever worked like that with random. They always pick a number the first time they run and then keep that number

    You have to set your self attribute and then a separate timer that says every 0 seconds change attribute to random(1,3) then use the attribute for your other timer duration be sure to check run to completion

    I just tried this, but it doesn't work.
  • 11clock11clock Member Posts: 450
    EDIT: Nevermind, I don't really know what's going on. The problem persists, though.
  • 11clock11clock Member Posts: 450
    Here is a picture of my current behaviors.



    Can someone please help me fix this issue?
  • entersimonentersimon Member, PRO Posts: 273
    One way to get around this would be to up the max in your RNG to 5 or so and instead of using a timer for the spawning you can use a rule like this:

    When Attribute 'self.random' = 3
    Spawn Actor

    You'll have to play with the max number a bit to get the timing feeling right, but this will work, plus it removes a timer, which in the long run will help out your performance.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Once you create a Timer with the Timer behavior, you cannot change its interval.

    So even though what you want when you do something like this:

    Timer
    Every random(1,9)
    .....

    is for the Timer to fire at intervals like 3,4,7,5,2,1,4,4,7, etc..., what actually happens is that the Timer randomly picks a number, and then keeps using that number as the interval. So you get the Timer firing at intervals like 3,3,3,3,3,3,3,3,etc...

    What you need to do is recreate, or "reseed" the Timer by wrapping it in a Rule.

    Something like this:

    First create a boolean attribute in the Actor called 'reseed'. Set this initially to true by checking the box.

    The set up your Rule structure like this:

    Rule
    When All conditions are valid:
    self.reseed is true
    .....Change Attribute: self.reseed To: false
    .....Timer
    .....After random(3,6) run to completion (set 3 and 6 to whatever interval you want)
    ..........Spawn Actor: darkness
    .....Timer
    .....After 0.5 run to completion
    ..........Change Attribute: self.reseed To: true

    Hope this helps!
    Joe

    p.s. also, in your above Rules, you have Run to Completion checked in a Timer that fires "every...". That is unnecessary.
  • 11clock11clock Member Posts: 450
    firemaplegames said:
    Once you create a Timer with the Timer behavior, you cannot change its interval.

    So even though what you want when you do something like this:

    Timer
    Every random(1,9)
    .....

    is for the Timer to fire at intervals like 3,4,7,5,2,1,4,4,7, etc..., what actually happens is that the Timer randomly picks a number, and then keeps using that number as the interval. So you get the Timer firing at intervals like 3,3,3,3,3,3,3,3,etc...

    What you need to do is recreate, or "reseed" the Timer by wrapping it in a Rule.

    Something like this:

    First create a boolean attribute in the Actor called 'reseed'. Set this initially to true by checking the box.

    The set up your Rule structure like this:

    Rule
    When All conditions are valid:
    self.reseed is true
    .....Change Attribute: self.reseed To: false
    .....Timer
    .....After random(3,6) run to completion (set 3 and 6 to whatever interval you want)
    ..........Spawn Actor: darkness
    .....Timer
    .....After 0.5 run to completion
    ..........Change Attribute: self.reseed To: true

    Hope this helps!
    Joe

    p.s. also, in your above Rules, you have Run to Completion checked in a Timer that fires "every...". That is unnecessary.



    This doesn't work. Now the object doesn't even spawn the darkness object.
  • ORBZORBZ Member Posts: 1,304
    even simpler:

    timer every 1s:
    chance = random(1,3)
    rule chance == 1:
    ... do stuff
  • 11clock11clock Member Posts: 450
    ORBZ said:
    even simpler:

    timer every 1s:
    chance = random(1,3)
    rule chance == 1:
    ... do stuff

    The problem with this is that the range will be from 1 to infinity. I want it to be every 1-3 seconds.

    If GameSalad can't do something as simple as doing something from 1-3 seconds, I may as well stop using GS. :/
  • gamedivisiongamedivision Member Posts: 807
    ive already done this your problem is your self.reset is not inside the other timer
    image

    Uploaded with ImageShack.us
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    yes gamediviosn is right
  • 11clock11clock Member Posts: 450
    gamedivisionuk said:
    ive already done this your problem is your self.reset is not inside the other timer
    <img src='http://img26.imageshack.us/img26/2733/screenshot20110627at212.png' />

    Uploaded with ImageShack.us



    Thank you, it finally works!
Sign In or Register to comment.