GameSalad

Howdy, Stranger!

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

Want random spawner to always spawn at least 2 objects

Hey guys! So basically how my spawner works is this:

  1. Every 0.3 seconds, it would pick a random number in the spawn attribute (1 to 10)
  2. When spawn attribute = 1, then spawn enemy at location X
  3. When spawn attribute = 2, then spawn enemy at location Y
  4. And so on... I have spawn commands set from 1 until 8 out of the 10, so when the random number goes to 9 or 10, nothing will spawn

How do I make it so that there's always going to be at least 2 enemies spawn at the same time?

Comments

  • tatiangtatiang Posts: 11,525Member, Sous Chef, PRO, Senior Sous-Chef

    For one thing, you're going to run into a problem caused by the way GameSalad rule conditions work. Rules only trigger/run when their condition(s) go from false to true. So for example, if you have a rule that says when spawnAttribute=1, [spawn at location x] and another rule that says when spawnAttribute=2, [spawn at location y]... then when the random number is chosen and it's 1, your first rule will fire. But if the next random number is also 1, your first rule will NOT fire. Because the rule was already true. It didn't switch back to false to reset, if you will.

    So... you need a way to get around that. And, um, I know of a way but I can't seem to find that thread. Perhaps I can find my demo.

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

  • tatiangtatiang Posts: 11,525Member, Sous Chef, PRO, Senior Sous-Chef

    I can't find it at the moment but here's the basic format:

    Change game.spawnAttribute to random(1,10)
    Timer after 0.1 seconds [run to completion checked]
         Change game.spawnAttribute to 0

    You may need a longer timer depending on how complex your rules are for spawning. But try 0.1 and increase from there as needed.

    Basically, it just resets the attribute value to 0 in-between the times it chooses a new value. That way, the rules you've created are ALWAYS false right before a number is chosen.

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

  • headhunterzsuckheadhunterzsuck Posts: 2Member

    Thanks! That seems to answer the question! :)

  • CasualEvolutionCasualEvolution Posts: 389Member, PRO

    Hi @headhunterzsuck depending of your code, another way to do the the reset of spawn attribute without a timer is do the reset in the spawned object.

Sign In or Register to comment.