Help With Basic Rule

freshfishfreshfish Member, PRO Posts: 49
Hello :)
I'm stumped!
I have two actors P1 and P2
and variables isP1Turn and number

This is an ongoing issue that I have isolated into a small task. You click on actor P1 and it should increase the number by 1 and then you click on P2 and increase by one…the actors take turns (i.e. P1 does not get two turns in a row)

Rule on P1:
When TOUCH RELEASED & isP1Turn=TRUE
Change Attribute number + 1
Change attribute isP1Turn to FALSE

I have a similar set up for P2 but it converts isP1Turn to TRUE

What happens is that I click on P1 and it works fine. Number goes up by one
I click on P2 and the number starts to go up by two and changes isP1Turn back to FALSE so I cannot click on P1

I have been stumped for 2 days on what should be a very simple task and I cannot understand why as the rules are straight forward

Any help is greatly appreciated
Thanks

Comments

  • mesaticusmesaticus Member Posts: 51
    I'm new to GameSalad so take this for what its worth....

    If it were me, I'd find True/Falses confusing. I might set my variable to actually state whose turn it is. So if P1 is clicked it changes the variable to "P2" (since it's their turn), and vise versa. You should be able to compare names in your rules. So if Name of Actor (P2) equals the variable of whose turn it is (P2)...do my actions and set variable to P1.

    As of right now, my guess is your oder of execution is off and it's not doing what you expect? Maybe post a screen??
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited August 2013
    Have a game attribute called Players Turn and set it as 1 by default.

    On player one actor have a rule that says:

    If (touch is released and game.Players Turn = 1) then
    increment your counter by 1
    change attribute game.Players Turn = 2

    On player two actor have a rule that says:

    If (touch is released and game.Players Turn = 2) then
    increment your counter by 1
    change attribute game.Players Turn = 1



    If you can find a smart way of switching 1 and 2 in one line you could have the one rule shared by both actors and set the player number in a self variable on each actor i.e. self.Player No.

    You would then change the rule to if (touch is released and game.Players Turn = self.Player No) then...

    I did see a post in the last week or so where someone showed how to toggle between 1 and 2 with one change attribute but I wasn't really understanding it at the time.
  • freshfishfreshfish Member, PRO Posts: 49
    Thanks guy for your comments.
    Kevin, I actually tried the PlayersTurn = 1 or 2 and it did the same thing

    Its almost as if the rule is still seeing the TOUCH state as released
    It is most bizarre

    P1 works fine, it increments by 1...P2 increments by 1, switches to P1 super fast and increments a second time. So I can only then press on P2 and it increments by 2 each time
  • freshfishfreshfish Member, PRO Posts: 49
    Let me add by saying if any experienced programmers (Java, Php, objective, etc) can give me an analogy...a control structure that functions like the RULE

    I'm accustomed to things like FOR Loops, or IF/ElSE statements that check a condition, run the lines of code procedurally and then loop back if the conditions still exist.

    I am nullifying the condition by changing the Player's Turn...argh :)
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Sounds strange! Unfortunately I'm not going to be near GameSalad for a couple of days so can't test it myself. Good luck finding a solution.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2013
    Hi @freshfish

    The solution from @KevinCross should work just fine... anyhow, maybe try a slightly different way: change the attribute back, i.e remake the PlayersTurn attribute to a boolean, and make sure you have 2 different number attributes, one for each of the actors:

    In your actor P1:

    Rule: When Touch is pressed AND PlayersTurn is false
    Change Attribute P1Num to P1Num+1
    Change Attribute PlayersTurn to true

    In your actor P2:

    Rule: When Touch is pressed AND When PlayersTurn is true
    Change Attribute P2Num to P2Num+1
    Change Attribute PlayersTurn to false

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    edited August 2013
    Hopefully this is what you're looking for. Try the project attached.

    EDIT: Oh! Gyroscope beat me to it!
  • freshfishfreshfish Member, PRO Posts: 49
    Oh my god! First thanks gyro and braydon for your assistance as well
    Looks like my code was all fine...but I had selected TOUCH = RELEASED and not TOUCH = PRESSED
    I wanted to avoid the issue with a lengthy "press" increasing the attribute until the person let go...but changing it to PRESSED solved the issue

    I feel dumb! :(
    Thanks
Sign In or Register to comment.