Changing Spawn Rate According To Score?

Tim_ATim_A Member, PRO Posts: 60
Hi all,

I'm trying to achieve something that i thought would be straightforward but is stumping me at the moment...

I'd like the spawn rate of the chosen actor to increase according to the score.

I have an integer for the score which works fine, and have added the attribute (integer) 'ratebirds' for the spawn rate, and set it to '3'.

For some reason, simply setting a rule that 'when score = 5, rate birds = 2' doesn't seem to work. I can't seem to use one integer to influence another?

Does anyone have any ideas?

Regards

Tim

Comments

  • Thunder_ChildThunder_Child Member Posts: 2,343
    I always use...like this...if equal OR GREATER THAN sign...especially if your score is able to jump in increments above your integer you want it to look for. I once told game at 10,000 to give free man...so to speak...but score jumped from 9,500 to 11,000 so it didnt see 10,000 register....when I said 10,000 or greater than....it worked. Hope this is what your looking for.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Here's the problem: attributes in timers do not update. So even though you'd think that having an attribute change value inside of a timer, the timer actually will always run with the initial duration. You'll need to use a custom timer for what you're trying to do. There's a big long complicated thread about this but since you're new, I'll give you a quick example:

    Create two real attributes called game.lastSpawnTime and game.spawnDuration. Set game.spawnDuration to how long you want to wait until the first spawn occurs (e.g. 3 would mean 3 seconds)

    Create this rule:

    When game.Time > game.lastSpawnTime + game.spawnDuration
         Spawn actor [actor name]
         Change attribute game.lastSpawnTime to game.Time

    Then, in any actor you like, you can change game.spawnDuration to adjust the frequency of spawning.

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

  • Tim_ATim_A Member, PRO Posts: 60
    Hi,

    thanks for the reply, that makes perfect sense why I couldn't get it to function properly!

    I've setup the above, and initially the timed spawn seems to works fine, but on scene reset, the spawn only works once then stops entirely?

    Do I have to reset the game.Time somehow?

    Regards

    Tim
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You can't change game.Time. Perhaps try changing game.spawnTime to game.Time at the top of the actor's rules (but not inside of a rule).

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

  • Tim_ATim_A Member, PRO Posts: 60
    Managed to sort it thanks to your help! Much appreciated, Tim
Sign In or Register to comment.