LOGIC PROBLEM WITH RULES

CodeCodeCodeCode Member Posts: 200
edited November -1 in Working with GS (Mac)
Logic Problem with Rules

So i have the following problem

I have attribute X = 0

and an actor with this rule

When touch released then
if "X = 0" then change attribute "X to 1"
if "X = 2" then change attribute "X to 3"
if "X = 4" then change attribute "X to 0"

its something like that, at the end of the rule the las command change the attribute back to 0.
The problem is when it comes back to 0 it keeps working and it changes 0 to the next number, in this case to 1 and i don't want that, i just want the actor back to its originals attributes (like restart the attribute) to pause there and to change attributes again when i released touch again.

So i hope someone can help me^^

Comments

  • osucowboy18osucowboy18 Member Posts: 1,307
    Prodigio said:
    When touch released then
    if "X = 0" then change attribute "X to 1"
    if "X = 2" then change attribute "X to 3"
    if "X = 4" then change attribute "X to 0"

    If you want to keep those statements, then a boolean game attribute might work. For example, create a boolean game attribute (game.BackToZero) and set it to false and then modify your rule above to this.

    When touch is released AND when game.BackToZero is false
    if "X = 0" then change attribute "X to 1"
    if "X = 2" then change attribute "X to 3"
    if "X = 4" then change attribute "X to 0"

    Change Attribute game.BackToZero to true

    The problem is you have created an infinite loop with your original rule. By adding game.BackToZero, you are only allowing the change in the X variable to happen once. By the way, if at some point down the road when you need to do the same procedure again, be sure to change game.BackToZero to false again. Hope that makes since. If you have any more questions, let me know.

    - Alex
  • CodeCodeCodeCode Member Posts: 200
    tshirtbooth no thats not the problem but thanks :-)
    osucowboy18 said:
    If you want to keep those statements, then a boolean game attribute might work. For example, create a boolean game attribute (game.BackToZero) and set it to false and then modify your rule above to this.

    When touch is released AND when game.BackToZero is false
    if "X = 0" then change attribute "X to 1"
    if "X = 2" then change attribute "X to 3"
    if "X = 4" then change attribute "X to 0"

    Change Attribute game.BackToZero to true

    The problem is you have created an infinite loop with your original rule. By adding game.BackToZero, you are only allowing the change in the X variable to happen once. By the way, if at some point down the road when you need to do the same procedure again, be sure to change game.BackToZero to false again. Hope that makes since. If you have any more questions, let me know.

    - Alex

    osucowboy18 exactly thats my problem, i cant find a way to stop the loop, i did what you told me creating an attribute game.BackToZero. But it doesn't work. The problem comes with the rule for bringing back attribute game.BackToZero to false.
    I tried to create a rule like this at the hole end

    after 2 Second change game.BackToZero to false

    but it doesn't stop the loop :-(

    By the way the hole thing is for a memory game with cards
    When i pick a card i shows a color, for every color i chose a number, like

    when red = 1
    when blue = 2
    when ...

    and an attribute called game.Color

    So when i press on a card and its blue then attribute game.Color changes to 2
    When i press on the next card if the card has the same number (if its the same color) then its ok
    but when its a different card like rule i want both to hide again and bring the attribute game.color to 0

    So every card has a code like that

    (in this case its the blue card)
    game.red = 0
    game.blue = 0
    game.color = 0
    self.open = 0

    when touch released
    if game.color = 0 change game.color to 2

    if game.color = 2 change game.color to 0
    change game.blue to 1 <- this attribute just indicates that you found both blue cards

    if game.color ≠ 0 or 2 change game.color to 0

    -------------------------------------------------
    The first if is when no other card is open
    The second if is when another card is open and the program compares if it is the same card
    The second if is when another card is open and the program compares if it is not the same card

    i did not put here the code for the attribute self.open i just use it for the images and some other things.

    Thats how i did it first but i did not work, then i tried to use the attribute game.BackToZero and put this on the third if

    change game.BackToZero to 1

    and a new rule on the actor to bring it back to 0 so they are hide and the people can keep searching for cards. i did this

    when game.BackToZero 1 and press released change game.BackToZero to 0

    but it did not stop the loop i tried to do it with time too like i said at the beginning but it doesn't work neither.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Instead of the 3 rules to check the value then recycle it, try,

    If touch released and X ≠ 1
    --Change Attribute X = (X+1)%5
Sign In or Register to comment.