Turning On/Off seperate move sets with the same button
lordsprinkles
Member Posts: 19
I'm not sure if my rules aren't correct or if it's a bug so here goes. Let's say I want the actor to have two move sets, a normal walk, run, etc. and then a sneaky walk, run, etc. I want to have 'Right Shift' activate and deactivate the Sneak move set. I create a rule for activating the sneak move set that says:
(All) requirements met;
>Right Shift = down
>Sneak Mode = False
>Facing Left = False [I have two rules for left and right facing so that it spawns the correct image depending on direction]
Then;
>Change Attribute: Sneak Mode to True [When this is True, it calls up the separate Sneak move rules and anims that only work when the Sneak Mode attribute is True]
>Change Image: to Sneak Image Idle
I would then have two movement rules with the Sneak Mode boolean attribute added. If false, it will animate the normal walk, etc. If true, then it will animate the Sneak walk, etc. The idea is to then press 'Right Shift' again to deactivate the Sneak move set and return it to the normal one. So I create this rule:
(All) requirements met;
>Right Shift = down
>Sneak Mode = True
>Facing Left = False [I have two rules for left and right facing so that it spawns the correct image depending on direction]
Then;
>Change Attribute: Sneak Mode to False [When this is False, it calls up the separate normal move rules and anims that only work when the Sneak Mode attribute is False]
>Change Image: to Normal Image Idle
However, when I add this last rule that would allow me to exit Sneak mode it breaks the animations move set. I would press Right Shift to enter Sneak mode and the image would change correctly but as soon as I start moving the image changes back to the normal move set animations instead of displaying the Sneak animations.
Here's the part I don't get. If I bind the rule that would deactivate Sneak mode to 'Left Shift' instead of trying to use the same button to deactivate it, it works perfectly. My movement rules are the same ones used in the Basic Platformer game that comes with GameSalad.
(All) requirements met;
>Right Shift = down
>Sneak Mode = False
>Facing Left = False [I have two rules for left and right facing so that it spawns the correct image depending on direction]
Then;
>Change Attribute: Sneak Mode to True [When this is True, it calls up the separate Sneak move rules and anims that only work when the Sneak Mode attribute is True]
>Change Image: to Sneak Image Idle
I would then have two movement rules with the Sneak Mode boolean attribute added. If false, it will animate the normal walk, etc. If true, then it will animate the Sneak walk, etc. The idea is to then press 'Right Shift' again to deactivate the Sneak move set and return it to the normal one. So I create this rule:
(All) requirements met;
>Right Shift = down
>Sneak Mode = True
>Facing Left = False [I have two rules for left and right facing so that it spawns the correct image depending on direction]
Then;
>Change Attribute: Sneak Mode to False [When this is False, it calls up the separate normal move rules and anims that only work when the Sneak Mode attribute is False]
>Change Image: to Normal Image Idle
However, when I add this last rule that would allow me to exit Sneak mode it breaks the animations move set. I would press Right Shift to enter Sneak mode and the image would change correctly but as soon as I start moving the image changes back to the normal move set animations instead of displaying the Sneak animations.
Here's the part I don't get. If I bind the rule that would deactivate Sneak mode to 'Left Shift' instead of trying to use the same button to deactivate it, it works perfectly. My movement rules are the same ones used in the Basic Platformer game that comes with GameSalad.
Comments
Right now the left and right shift keys send the same event.
Here is a suggestion on how to break this up:
Instead of having specific left sneaking and right sneaking, just have one rule that will toggle the sneak on and off.
Change Attribute: 'sneaking' => ('sneaking' +1)%2
On your moving rules try this:
Rule: If key pressed 'right' is down
-> Rule: If Attribute Changed 'sneaking' is true
-> -> Animate (sneaking animations). Return
-> -> Move behavior: Right at a slower speed
-> ...Otherwise
-> -> Animate (normal animation)
-> -> Move Behavior: Right at normal speed
Right now the left and right shift keys send the same event.
Here is a suggestion on how to break this up:
Instead of having specific left sneaking and right sneaking, just have one rule that will toggle the sneak on and off.
Change Attribute: 'sneaking' => ('sneaking' +1)%2
On your moving rules try this:
Rule: If key pressed 'right' is down
-> Rule: If Attribute Changed 'sneaking' is true
-> -> Animate (sneaking animations). Return
-> -> Move behavior: Right at a slower speed
-> ...Otherwise
-> -> Animate (normal animation)
-> -> Move Behavior: Right at normal speed
Can you explain what this means?
Change Attribute: 'sneaking' => ('sneaking' +1)%2
What is happening in the script when this function is called? I've never seen a '%2' within a function on tutorials I've read. Is the +1 another way of calling it to be True?
The way modulus works, it give the remainder.
e.g. 0%2 = 0, 1%2 = 1, 2%2 = 0
With boolean to set it to false the value is 0. And True is 1.
% = modulus. So, with x%y, you take the remainder of x/y.
The key to understanding is knowing that you're only dealing with whole numbers. For 1%2, you only want to know how many times 1 is wholly divisible by 2 and then take the remainder. So, how many times does 2 go into 1? 0 times. 1 is left over because it couldn't be wholly divided by 2.
Now, take 3%2 as an example. How many times does 2 go into 3? 1 time. That leaves a remainder of 1.
You can try thinking of it this way: Since 2 goes into 3 one whole time, 2 * 1 = 2. 3 - 2 = 1, the remainder.
6%6 would be 0. (6 is wholly divisible by 6 one time, with nothing left over). 6*1 = 6. 6-6 = 0, the remainder.
22%7 would be 1. 22/7 = 3, remainder 1. (in other words ( 7 * 3 = 21. 22 - 21 = 1, the remainder))
For your question, sneaking is a boolean value, which means it always has a value of 1 or 0. 1 for true or 0 for false. If you were always doing modulus on the boolean 'sneaking' + 1 you would never have 0%2.
Your end result is always going to be 1 or 0 for the line you're talking about.
Say sneaking = false = 0. Then:
(0+1)%2 = 1%2 = (the remainder of 1/2) = 1
Sneaking = true = 1. Then:
(1+1)%2 = 2%2 = (the remainder of 2/2) = 0
Rule: If key pressed 'right shift' is down
-> Change Attribute 'self.Sneak Mode' => ('self.Sneak Mode'+1)%2
I press right shift but nothing happens. The sneak mode works b/c I can use this rule
Rule: If key pressed 'right shift' is down
-> Change Attribute 'self.Sneak Mode' => 1
and it will turn on the correct sneaking animations.
That's my mistake. I was writing that off the top of my head. Instead of a boolean, make it an integer, and in the condition, check if it is 0 or 1, instead of false or true.