Setting spawn limit in endless survival game.

zefrofzefrof Member Posts: 26
edited July 2012 in Working with GS (Mac)
I have a set of attributes (wavenumber, badguys, and start round) and a set of rules:

image

image

When an enemy is killed it subtracts 1 from bad guys. When bad guys equals 0 it adds one the the wave number and changes bad guys to 2*wavenumber.

image

Currently it's set to spawn every 3 seconds. I want it to only spawn the number of bad guys needed to beat a wave. I've tried this but it wouldn't spawn enemies on wave 2.

image

Is it as simple as changing the conditions for spawning or do I need to do something else?

Best Answers

  • MotherHooseMotherHoose Posts: 2,456
    Accepted Answer
    @zefrof … problem may be:
    changeAttribute: game.waveNumber is not changed at correct time

    on the Rule: when
    Attribute: game.startRound is true
    Attribute: game.BadGuys = 0
    -changeAttribute: game.waveNumber To: game.waveNumber+1
    -changeAttribute: game.startRound To: false

    on the Rule: when
    Attribute: game.startRound is false
    -changeAttribute: game.BadGuys To: 2*waveNumber
    -changeAttribute: game.startRound To: true

    image MH
  • tatiangtatiang Posts: 11,949
    Accepted Answer
    Try adding a buffer to the For timer so that it says 2*game.wavenumber+0.5, as I suggested above. In testing, that worked for me.

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

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Usually, I find that I need to add a small buffer to the For timer to allow it to successfully iterate through the Every timers. So my For timer would be something like game.badguys+0.3. What exactly is happening when you try to use game.badguys as the For timer value? Do you end up with one less than game.badguys?

    Another way to limit bad guys would be to have each bad guy change attribute game.badguyCount to game.badguyCount+1 and then add a condition to your Spawn Actor behavior that says When game.badguyCount<game.badguys.

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

  • ericzingelerericzingeler Member Posts: 334
    edited July 2012
    Not sure if you are already doing this, you want to count your dead bad guys at point of death so you can remove that check timer. At spawn time, on a per actor basis, subtract from the dead bad guy count.

    To spawn correct amount of bad guys, do something like this:

    1. Every 3 seconds:
    - Change attribute [StartSpawn] = 1

    2. If [BadGuyCount] > 0:

    (Inside of Rule 2)
    2a. If [StartSpawn] = 1:

    (Inside of Rule 2a)
    2a-a. Every 0 seconds:
    - Spawn Bad Guy
    - Change Attribute [BadGuyCount] to [BadGuyCount]-1

    Otherwise (For Rule 2):
    Change Attribute [StartSpawn] = 0

    I say something like this because I it may need to be tinkered with.
  • zefrofzefrof Member Posts: 26
    @tatiang When I use game.badguys in the timer the first wave runs fine but as soon as wave 2 starts nothing spawns.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    In your Next Wave rule, try adding a condition for scene.time > 0.5 (or wrap the whole rule in an after 0.5 timer). It could be that when your scene starts, that rule is running before any enemies are spawning. I've had that problem before and a timer solved it.

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

  • zefrofzefrof Member Posts: 26
    edited July 2012
    @tatiang I tried adding a timer it didn't work. Have any other ideas?
  • zefrofzefrof Member Posts: 26
    By changing the rules to like @MotherHoose said (thanks) and by making the spawn like so:

    attribute: game.startround is true
    attribute: game.badguys = 2*game.wavenumber
    timer:
    for 2*game.wavenumber
    every 1 sec spawn enemy

    It will run the first wave fine and even start the second wave now, but the second wave only spawns 3 enemies when it needs 4 to finish the wave. Anybody think of what I can do to fix it?
  • zefrofzefrof Member Posts: 26
    @tatiang that made it work perfectly! Thanks everybody for the help!
Sign In or Register to comment.