Want random spawner to always spawn at least 2 objects
headhunterzsuck
Member Posts: 2
Hey guys! So basically how my spawner works is this:
- Every 0.3 seconds, it would pick a random number in the spawn attribute (1 to 10)
- When spawn attribute = 1, then spawn enemy at location X
- When spawn attribute = 2, then spawn enemy at location Y
- 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
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
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
Thanks! That seems to answer the question!
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.