Random Time Spawning Help

I'm working on a game that requires that an actor is spawned at random, between say 2 and 6 seconds. As the game gets harder, the range will get more challenging. I can't seem to get it to do this. I've tried everything that I can think of. The obvious way would be to make a timer, and say
every random(2,6) seconds spawn actor
Except the only thing that does is pick one of those times and stick with it for the duration of the game.
After that I tried
every random (random.time) seconds: spawn actor, change attribute (random.time) to random(2,6).
Still nothing.
Any help at all would be appreciated
-Tim
every random(2,6) seconds spawn actor
Except the only thing that does is pick one of those times and stick with it for the duration of the game.
After that I tried
every random (random.time) seconds: spawn actor, change attribute (random.time) to random(2,6).
Still nothing.
Any help at all would be appreciated
-Tim
Comments
have a rule for it in the scene
every 2 seconds
change attribute randomspawntimer to random (2,6)
then somewhere else possibly your spawning location
if randomspawntimer = 2
then spawn (actor x)
if randomspawntimer = 3
after 1 second spawn (actor x)
if randomspawntimer = 4
after 2 seconds spawn (actor x)
if randomspawntimer = 5
after 3 seconds spawn (actor x)
if randomspawntimer = 6
after 4 seconds spawn (actor x)
try that
The flaw is that because it's picking it every two seconds, there is about a 1/3 chance that the numbs are 4 apart -- like for example, it picks 5 which spawns after 3 seconds and then two seconds later it picks 2 which spawns immediately. So you have two penguins spawning within 1 second when the range is supposed to be 2-6.
Still though, I've been playing with the numbers and I think that I can get it to do pretty much what I want. At least this way is somewhat random.
Gamesalad really needs to make a way to do this though, it seems like I'm not the only one who would find this useful...
Thanks
-Tim
all you have to do is have a global attribute integer or boolean lets call it SPAWNTAKEN.
when the actor is spawned change the attribute to true or 1. when it is destroyed change the attribute back to false or 0
and in the spawning actor make sure your spawning rule is set to take effect only when SPAWNTAKEN = 0 or false
so the following will be included with your exsisting spawning rules
[ rule when attribute game.SPAWNTAKEN = 0 ]
penguin1, pengiun 2 etc
when the penguin is spawned you could change a global attribute. lets use your example and we'll make a global attributes named PENGUIN5 and another for PENGIUN2.
in the spawning rules for certain situations. like the above.
when pengiun5 is spawned change the global attribute for PENGIUN5 to on
you could have a another randomspawntimer attribute lets call it randomspawntimer2 that has the following
change attribute randomspawntimer to random (3,6)
now have a selector that selects which spawn timer to use. lets call it whichtimer 0/1
.
.
rule when game.PENGIUN5 is on
change attribute game.whichtimer to 1
rule when game.PENGIUN5 is off
change attribute game.whichtimer to 0
.
.
rule game.whichtimer = 0
every 2 seconds
change attribute randomspawntimer to random (2,6)
.
.
.
rule game.whichtimer = 1
every 2 seconds
change attribute randomspawntimer to random (3,6)
havnt tested that just flying it off the top of my head. might be buggy. lol but let me know
Also just to let you know I don't mind more than one on the screen at the same time, but if they are too close together than it makes the game very difficult--which I wouldn't want for the first 30 seconds or so. The game is supposed to get harder as time goes on, so eventually the spawning within one second wouldn't be an issue.
Anyway I'll get back to you once I've tried out your methods.
Thanks again!
-Tim