GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Creating endless rounds of enemies with timing

saad1993saad1993 Posts: 47Member, BASIC

So I have a single enemy character that comes into scene and then increases its speed towards the player. I want to be able to create endless rounds of these enemies with about 3 to 4 seconds of a gap in between, like a breather, and increasing acceleration in every round.

I created a real attribute called gamerealtime and increased by 1 second every real second. In the enemy actor, I used that to spawn enemy actor for 12 seconds and then stop from 13 to 16 seconds. That was one rule, with an increase in linear velocity in X axis from -100 to -210. Second rule, increased speed to -240 and so on.

I have used a trigger to spawn and not-spawn enemy character. Boolean attribute called spawnenemy. Spawn actor is separate and hidden. In enemy actor, the attribute spawn enemy is triggered on in all the individual rules. For example, a rule named speed -210 will have: When gamerealtime is lessthan/equalto 12 and greaterthan/equalto 0, do changeattribute spawnenemy to true, timer every 0.3 secs changeattribute self.motion.linearvelocity.x to self.mot.... - 210.

The last part sort of brings the enemy in slow and then accelerates all of a sudden to the player.

The problem is, my rounds aren't working. The boolean is set to true initially. The first round spawns (-210), and the second round does (-240), third round and so on do not. I cannot figure out why.

Need help figuring this out.
Thanks!

Comments

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

    @saad1993 said:
    I created a real attribute called gamerealtime and increased by 1 second every real second.

    This attribute already exists, game.time increases at the same rate, without the need for any rules or timers (and so on).

    @saad1993 said:
    When gamerealtime is lessthan/equalto 12 and greaterthan/equalto 0, do changeattribute spawnenemy to true . . .

    You could do this more simply with:

    When game.time%16 < 12
    --Spawn some stuff

  • saad1993saad1993 Posts: 47Member, BASIC

    @Socks said:

    You could do this more simply with:

    When game.time%16 < 12
    --Spawn some stuff

    Could you explain that to me? I have a separate hidden spawn actor for spawning. Plus I don't understand the % sign.

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

    @saad1993 said:
    Could you explain that to me? I have a separate hidden spawn actor for spawning. Plus I don't understand the % sign.

    @tatiang has a better (more correct) understanding of modulus (the '%' sign), my own interpretation is that modulus 'loops' around the modulus value.

    So game.time normally increases like this . . .
    game.time = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 . . . and so on.

    But if you were to use game.time%5 then . . .
    game.time = 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 . . . and so on.

  • zweg25zweg25 Posts: 738Member

    @Socks said:
    But if you were to use game.time%5 then . . .
    game.time = 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 . . . and so on.

    I believe game.time%5 would actually loop like: 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4

    That being said, I don't remember, but I thought game.time increases by 1 every millisecond or some smaller time interval than seconds

  • SocksSocks London, UK.Posts: 12,822Member
    edited September 2016

    //

  • tatiangtatiang Posts: 11,845Member, Sous Chef, PRO, Senior Sous-Chef
    edited September 2016

    Modulus is the remainder of a division operation. So for example, if you divide 6 by 4, the remainder is 2. So you could also write this as 6÷4=1 R 2 or as 6%4=2. Another example is if you divide 6 by 10, the remainder is 6. So you could write it as 6÷10=0 R 6 or as 6%10=6. As @Socks explained, modulus is useful for looping values:

    game.Time     game.Time%16    game.Time%16 < 12 ?
    —————      ———————     ———————————
    0                    0                         yes (spawn enemy!)
    1                    1                         yes
    2                    2                         yes
    3                    3                         yes
    ...                  ...
    11                 11                         yes
    12                 12                         no
    13                 13                         no
    14                 14                         no
    15                 15                         no
    16                 0                           no
    17                 1                           no

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • saad1993saad1993 Posts: 47Member, BASIC

    @tatiang said:
    Modulus is the remainder of a division operation. So for example, if you divide 6 by 4, the remainder is 2. So you could also write this as 6÷4=1 R 2 or as 6%4=2. Another example is if you divide 6 by 10, the remainder is 6. So you could write it as 6÷10=0 R 6 or as 6%10=6. As @Socks explained, modulus is useful for looping values:

    game.Time     game.Time%16    game.Time%16 < 12 ?
    —————      ———————     ———————————
    0                    0                         yes (spawn enemy!)
    1                    1                         yes
    2                    2                         yes
    3                    3                         yes
    ...                  ...
    11                 11                         yes
    12                 12                         no
    13                 13                         no
    14                 14                         no
    15                 15                         no
    16                 0                           no
    17                 1                           no

    Im not entirely sure where and how to use this to spawn enemies. Is this a string or numeric expression rule?

  • SocksSocks London, UK.Posts: 12,822Member
    edited September 2016

    @saad1993 said:
    Im not entirely sure where and how to use this to spawn enemies. Is this a string or numeric expression rule?

    It's a mathematical operation, so for example you could use it in a numeric expression:

    When game.time%16 < 12
    --Spawn some stuff

  • SocksSocks London, UK.Posts: 12,822Member
    edited September 2016

    @tatiang said::

    game.Time     game.Time%16    game.Time%16 < 12 ?
    —————      ———————     ———————————
    0                    0                         yes (spawn enemy!)
    1                    1                         yes
    2                    2                         yes
    3                    3                         yes
    ...                  ...
    11                 11                         yes
    12                 12                         no
    13                 13                         no
    14                 14                         no
    15                 15                         no
    16                 0                           yes
    17                 1                           yes

    :* :)

Sign In or Register to comment.