LOGIC PROBLEM WITH RULES
CodeCode
Member Posts: 200
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^^
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
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
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.
If touch released and X ≠ 1
--Change Attribute X = (X+1)%5