Timer within a timer?
j_d_campbell98
Member, PRO Posts: 12
Hi noob here. I'm trying to make a timer within a timer so that basically after 10 seconds an enemy is spawned every 4 to 8 seconds but instead the enemy only spawns every 10 seconds.
StartTime and Mod1 are both real attributes I made, StartTime is at 0 and Mod1 is at 0.05.
My code goes a bit like this:
If self.time > game.StartTime + 10
then
If game.mod1 > self.time % random(4, 8)
then
Spawn Enemy.
I'm using Attribute timers rather than actual timers, obvs.
Please Help!
Comments
What about using an actor to spawn the spanner after 10 seconds?
You could have a dummy actor that looks like it and after self.time>10 destroy and spawn a different actor that spawns random(4,8)
@j_d_campbell98
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
Ahhh I was way over thinking that thanks!
Another problem I have is that although they're only meant to spawn every 4 to 8 seconds they sometimes spawn a lot quicker and sometimes two actors are spawned at the exact same time and I'm really confused
I'm pretty sure it's got something to do with the random(min, max) part as it works fine if I were just to put in a single number.
@j_d_campbell98 can you post a screenshot of the spawning code? You are sure that you only have one of the spawning actors on the scene? Is it wrapped in a timer maybe?
MESSAGING, X-PLATFORM LEADERBOARDS, OFFLINE-TIMER, ANALYTICS and BACK-END CONTROL for your GameSalad projects
www.APPFORMATIVE.com
Hey @j_d_campbell98,
I would do this one on two ways.
~First Way~
When game.start is true
After 10 seconds
Every random (4,8) seconds
Spawn enemy
~Second Way~
Create a game boolean attribute called spawn_enemy
When game.start is true
After 10 seconds
Change attribute game.spawn_enemy to true
When game.spawn_enemy is true
Every random (4,8) seconds
Spawn enemy
When game.over is true
Change attribute game.spawn_enemy to false
Those are the two ways I would approach this! Hope it helps!
Also don't hate me but I'm using a PC. I just used this thread cause it has like 40k questions and seemed more likely for an answer
You cannot have random value in a timer, well you can, but it will only use the first value it generates . . . which makes sense, because 'every' means 'each one' / 'all of them' - so it doesn't really make sense to say 'all of . . . ' and then only use a value once (which is the case with a changing random value).
A: When are you open.
B: We are open every Saturday.
A: Ok, cool, I can't make this Saturday, but I can visit next Saturday.
B: We're not open next Saturday, the days we are open change randomly.
A: But you said 'every' Saturday ?
B: Yeah like I say, the days we are open change randomly, it might be every Saturday, then every Tuesday, then every Monday . . .
A: WTF ?
This is how I would do it.
A game attribute called X.
. . . . . . . .
Rule for the Spawner actor:
Timer
--After X seconds
---Change X to random(4,8)
---Spawn Enemy
---Destroy this actor
---Spawn Spawner
Example (attached)
@Socks Method works pretty good.
But here is my way of doing it without using timers or spawning and destroying actors. I configured it to do exactly what you needed.
Let me know what you think.
Demo attached.
Here is a screenshot of the rules:
Fortuna Infortuna Forti Una
Thanks guys, this all really helps