Weird actor spawning
Zourath
Member Posts: 16
So in the first game I was making, I had a problem with lag. I think I finally found the cause, but I don't know how to fix it. I have an actor that is supposed to spawn one actor at random from a set of five every second. But it appears to spawn more than one. Here is how the actor is set up.
Every second it changes the attribute self.chance to a number between 1 and 5. after that, in the same timer, there is a rule that checks to see if self.chance is a one. If it is, it spawns an actor. It then goes to another rule that checks to see if self.chance equals a 2, and spawns a different actor if true...etc, etc. The problem is there should be no point in which it can spawn more than one actor, since it should change self.chance only once per second, and always before it checks to see what number self.chance is.
Every second it changes the attribute self.chance to a number between 1 and 5. after that, in the same timer, there is a rule that checks to see if self.chance is a one. If it is, it spawns an actor. It then goes to another rule that checks to see if self.chance equals a 2, and spawns a different actor if true...etc, etc. The problem is there should be no point in which it can spawn more than one actor, since it should change self.chance only once per second, and always before it checks to see what number self.chance is.
Comments
i also had some problems with lag due to the use of random.
I'll take a look at that. But for now, did you check that you don't have anything in your otherwise clauses?
Try this:
Make 2 attributes: randomSpawn (integer) and doSpawn (boolean)
Timer (Every 1 second)
-> Change Attribute: game.randomSpawn = random(1,5)
-> Change Attribute: game.doSpawn = 1
Rule: An attribute changes- game.doSpawn is true
-> Rule: Attribute Changes: game.randomSpawn equals 1
-> -> Spawn Actor: 1
-> -> Change Attribute: game.doSpawn = 0
-> -> Change Attribute: game.randomSpawn = 0
-> Rule: Attribute Changes: game.randomSpawn equals 2
-> -> Spawn Actor: 2
-> -> Change Attribute: game.doSpawn = 0
-> -> Change Attribute: game.randomSpawn = 0
...
-> Rule: Attribute Changes: game.randomSpawn equals 5
-> -> Spawn Actor: 5
-> -> Change Attribute: game.doSpawn = 0
-> -> Change Attribute: game.randomSpawn = 0