Random spawning of actors doesn't always work?
I've made a rule for a group of actors that says that if they collide with another actor, they will change an integer attribute to a random value from 1 through 8, which will determine which actor gets spawned next, since there are 8 actors in this group. However, I've applied this rule for each individual actor but it doesn't always work. Sometimes it works 7 times in a row, sometimes 13 times in a row, sometimes only once or twice in a row, every time I try it. But sometimes when an actor collides with another, it doesn't spawn another random actor like it's supposed to. Here's a screenshot of my code:
The Change Attribute behavior that says "set game.pickActor to random(1, 8)" is how I spawn a random new triangle, since each triangle is assigned a number from 1 through 8. How do I make it so that it spawns a new triangle every time the existing triangle collides with the petal? It's not always working for some reason. I know it's not because I've included "Destroy this actor" with my two change attributes, because I removed that behavior from each triangle and the problem still persists. I also know it has nothing to do with repeating actors, because I've gotten two triangles of the same color and the problem still occurred afterward. What should I do?
Comments
I think this may well be the problem, if you had a pattern that went [2 7 8 4 3 0 1 6 6] the second 6 might not fire depending on how the spawner is set up.
I explain this problem (repeating random values do not trigger a rule) and provide a solution at http://forums.gamesalad.com/discussion/comment/513319/#Comment_513319.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I tried the solution by setting the rules exactly as you had in the "Random with repeats" project and now it just spawns a new triangle every second. I've even checked "run to completion" and it still spawns multiple actors at once, when I only want to spawn a new triangle when a triangle is destroyed. Is there a way to have it only be one at a time?
My guess was that you weren't seeing multiple iterations of the rule because the random(1,8) was generating repeat values such as 3, 5, 5, 7, 8 -- which would only trigger the rule condition to be true at 3, 5, 7 and 8 (four times instead of five).
It sounds like you have a different issue related to collision detection. But there's not enough information there for me to suggest anything else. I would say to isolate the collision rules and see if they are triggering as expected.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User