Timer within a timer?

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

  • DaftbombDaftbomb Member Posts: 36

    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)

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @j_d_campbell98‌

    change attribute self.SpawnTime=game.Time+10
    
    Rule: if self.SpawnTime<game.Time then
    
             spawn Enemy
             change attribute self.SpawnTime=game.Time+random(4,8)
    
    end if
    
  • j_d_campbell98j_d_campbell98 Member, PRO Posts: 12

    Ahhh I was way over thinking that :D thanks!

  • j_d_campbell98j_d_campbell98 Member, PRO Posts: 12

    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

  • j_d_campbell98j_d_campbell98 Member, PRO Posts: 12

    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.

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @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?

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    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!

  • j_d_campbell98j_d_campbell98 Member, PRO Posts: 12

    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 :(

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    @KillerPenguinStudios said:
    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!

    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 ?

    :smile:

  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2015

    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

  • SocksSocks London, UK.Member Posts: 12,822

    Example (attached)

  • LovejoyLovejoy Member Posts: 2,078
    edited January 2015

    @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

  • j_d_campbell98j_d_campbell98 Member, PRO Posts: 12

    Thanks guys, this all really helps :)

Sign In or Register to comment.