spawning on a random timer

SparkyidrSparkyidr Member Posts: 2,033
edited November -1 in Working with GS (Mac)
Having a bit of trouble with this (I know the random thing is not random....but anyways)

I want to spawn some actors offscreen, and then move onto the screen at a set speed. But I want the gap between actors to be slightly different each time.

So I have a rule :
---
Every random (1,2) seconds
Spawn actor x=600 y=(random 20,120)
---

The random y value works a treat...but the timer, just picks either 1 second, or 2 seconds at the start of the scene, and ALWAYS uses that time delay.

I had assumed random 1,2 seconds would give me a random time interval from 1.0 -2.0 seconds. But like I say.. at the start of the scene, it picks either 1, or 2, and sticks to it.

Have I got this totally wrong?????

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    The random function will only give you integers.

    So random(1,2) will give you either 1 or 2, not 1.3 for example.

    Ideally the Timer would behave like you mentioned.
    I have a lightning actor on my main menu that crashes every few seconds. I wanted the intervals between crashes to be random as well.

    To do that, you have to "reseed" the Timer...

    Try this:

    Create a boolean attribute in the Actor called 'reseed'. Set it initially to true (check the box).

    And set up the Rule set something like this:

    Rule
    When all conditions are valid:
    self.reseed = true
    -----Change Attribute: self.reseed To: false
    -----Timer: After random(1,2) seconds
    ----------[spawn Actor]
    -----Timer After 0.5 seconds , run to completion
    ----------Change Attribute: self.reseed To: false
  • SparkyidrSparkyidr Member Posts: 2,033
    Joe....I love you.
  • millerbrother1millerbrother1 Member Posts: 108
    Hmmm. This doesn't work for me for some reason. I even tried changing the last line of your code from Change Attribute: self.reseed to: true (instead of false). Are we sure this works? The logic looks right, but my game won't cooperate with it. :-(
  • zombie_farmzombie_farm Member Posts: 33
    Im missing it to.. is there a way you could post a little project?
    thanks
  • zombie_farmzombie_farm Member Posts: 33
    I have tried it with self and game. also are both of the to set the reseed to false? how does it get turned back on?
Sign In or Register to comment.