Weird actor spawning

ZourathZourath Member Posts: 16
edited November -1 in Working with GS (Mac)
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.

Comments

  • nulonulo Member Posts: 315
    it spawns more than 1 at the exact same time!? or between the "1 second"?

    i also had some problems with lag due to the use of random.
  • ZourathZourath Member Posts: 16
    At the exact same time. I didn't even know there was a bug until I tested the weapon designed to destroy them, but had only programmed it to destroy one color.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Hi Zourath and nulo,
    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
Sign In or Register to comment.