Randomizer triggering both possible behaviors

BacktothisBacktothis Member, PRO Posts: 75
edited March 2014 in Working with GS (Mac)
This is an extremely simplified down version of a question I asked a couple days ago that wasn't able to be resolved. I've narrowed it down as follows:

Initialize State:=1

Timer every 1 second
-->When game.State = 1
---->DisplayText "1"
---->Otherwise
------>When game.State = 2
--------->DisplayText "2"
-->game.State = random(1,2)

What happens is that sometimes, "1" will be displayed, sometimes "2" will be displayed, and sometimes both "1" and "2" will be displayed. Whatever is causing the "1" and "2" at the same time behavior explains my previous problem.

The project file I uploaded to http://www.filesnack.com/files/ct9qdilj
All the logic is in the spawner actor and is literally as short as it sounds but I can't figure out what I'm missing.

edit - look at the spawner on the scene not the prototype, I just noticed the prototype is a super old version that is out of date because it referenced variables that were cut out to simplify the problem as I was trying to figure it out.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2014
    It could just be me -- and I actually have a programming background -- but I find it much easier to help you if you write in GS "code' (Timer every 1 second --> When game.state (integer)=1 --> DisplayText "1", etc.).

    Anyway, I'll take a look at the file...

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

  • BacktothisBacktothis Member, PRO Posts: 75
    Ah ok, well let's see then...

    Timer every 1 second
    -->When game.State = 1
    ---->DisplayText "1"
    ---->Otherwise
    ------>When game.State = 2
    --------->DisplayText "2"
    -->game.State = random(1,2)
  • BacktothisBacktothis Member, PRO Posts: 75
    I tried to indicate the nesting order there, not quite sure how readable it is though lol
  • BacktothisBacktothis Member, PRO Posts: 75
    Just a clarification also to look at the spawner that is actually on the scene rather than the prototype. The prototype is an older version that reference lots of variables that are no longer there. I cut most of them out in the process of trying to simplify and figure out the root cause of the issue.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I can see your logic and it seems pretty sound. The only thing I would change (and this is in fact the fix) is to take the rule out of the timer. The timer should just be changing the random value. The condition doesn't need to be in a timer at all. And though it's tricky to explain why your method didn't work, I think it has to do with the change of attribute coming after the rules... so the rules won't actually fire until the timer cycle starts again, and then it immediately picks another value for the attribute and well, I guess the rule fires immediately before the timer ends. It's confusing so why not make it simpler? ;)

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

  • BacktothisBacktothis Member, PRO Posts: 75
    Hmm, the timer is to control how far apart things spawn, but I guess I could have an attribute called ReadyToSpawn or something that also gets set to true when the timer fires? Unless there's an even simpler way to do it.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Actually, sorry... I take it back. It won't work because if you choose the same random value again the rule won't fire. So maybe you do need it inside of the timer. Try moving the change attribute behavior above the rule so that it runs first.

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

  • BacktothisBacktothis Member, PRO Posts: 75
    Wow, taking the rule out of the timer actually fixes it. I'm so surprised lol . So somehow the change attribute manages to go from the old to the new value while the rule is being evaluated and so it evaluates both values? I still don't quite understand how

    When game.State = 1

    can be simultaneously evaluated as true and false even with some strange order of the random function being executed... but wow lol. Thanks a lot xD
  • BacktothisBacktothis Member, PRO Posts: 75
    edited March 2014
    http://www.filesnack.com/files/cd1iwcj1

    The fix in all its humor lol. Taking it out did miracles.

    edit - Also I did all sorts of moving order around with the timer. The problem is literally if it stays in the timer, no matter what order it's in, it will bug out like that. Even if you put the random function AFTER the display text, within each rule block, it will bug out.

    So like

    When game.State = 1
    -->Display 1
    -->game.State=random(1,2)
    Otherwise
    -->When game.State = 2
    ---->Display 2
    ---->game.State=random(1,2)

    Even that won't work right. And the timer is a 1 second timer so you'd think that the commands would definitely have plenty of time to execute but idk lol. Either way taking the rule out of the timer fixes it.
  • BacktothisBacktothis Member, PRO Posts: 75
    A further note after testing in my full game. It's not the timer that causes the problem. The random function and the actual other stuff that use the variable affected by random() simply cannot be in the same nested level, be it a rule or a timer or whatever. If they are together then that weird behavior happens where the equality rule gets evaluated as both true and false. As long as they are separate everything works.
Sign In or Register to comment.