Random spawn
Snivy123454321
Member Posts: 8
I need to some actors to spawn at random intervals. If I use a timer with random(min, max), it will take a random number and use it every time until the game is restarted. Any ideas?
Comments
http://forums.gamesalad.com/discussion/comment/464547/#Comment_464547
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Yes, that's what 'every' means, it means all the members of a set, so it doesn't make sense to have 'every' and then a changing value.
When are you open ?
We open every Saturday.
Oh great, I'll be in town next month, so I will pop in on a Saturday.
I wouldn't risk it if I were you.
What do you mean ?
We might not be open on Saturday.
But you said you were open every Saturday.
Yes, every Saturday for the first day then a different random day every day after that.
WTF?
. . . . . . . .
So . . . you are asking GameSalad to generate a random number and then use that random number every time it cycles around, so it is working exactly as it should, for example the random number chosen is three, so three is used every time.
I'd produce a random timer like this:
Make a game attribute, let's call it X.
In the spawner actor:
Timer, After X seconds
. . . Spawn what needs to be spawned
. . . Change X to a random number
. . . Destroy this actor
. . . Spawn the spawner actor.
Socks, you misunderstood, I want random intervals, so 3 seconds the first time, then 4 the next, then 2, etc.
Tatiang's setup works, but thank god for copy/paste, because i have no idea what just happened
Change self.duration to random(3,7)
First, we set an initial duration for the timer
If game.Time ≥ self.timeStamp+self.duration
The timeStamp is set to game.Time whenever the timer runs. So let's say the timer first runs at game.Time=0 and self.duration is 4. After 4 seconds, game.Time=4 and self.timeStamp+self.duration=0+4, so the rule triggers again.
Change self.duration to random(3,7)
At that point, self.duration chooses a new value -- let's say 6.
Change Attribute self.timeStamp to game.Time
And self.timeStamp gets set to game.Time which is now 4. That rule will trigger again when game.Time is 4+6 or 10 seconds.
And then we repeat the process!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thanks, that makes a lot more sense now
After setting this up, how do we use this?
Yes, that's what my method (above) does.
EDIT: just realised this post is over a year old, whoops, sorry for the late reply
@saad1993 Just replace the Log Debugging Statements with whatever you want to happen during each loop.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User