Logic / Nesting
echoink
Member Posts: 11
Can someone help me with some basic command nesting?
My game is working well enough, but I'm noticing some quirks in my logic. For movement, I have four basically similar commands
Group: Movement
Right Move Rule
When all of the following
when right arrow key is pressed,
if self position is X
move in direction
constrain self.rotation to...
animate
Left Move Rule
When all of the following
when left arrow key is pressed
if self position is X
move in direction
constrain self.rotation to...
animate
so on an so forth for the up and down arrow keys.
The constrain self.rotation, and the animate are redundant, and for that matter, I it seems an "if any" conditional would work better.
Something like this:
Group: if any: key press right, key press left, key press up, key press down)
Group do: (move in the direction arrow is pressed, constrain self.rotation, animate
But I seem to be placing the constrain self.rotation and the animate int he wrong spot because when I try to group them in a way that seems more efficient, things break.
My game is working well enough, but I'm noticing some quirks in my logic. For movement, I have four basically similar commands
Group: Movement
Right Move Rule
When all of the following
when right arrow key is pressed,
if self position is X
move in direction
constrain self.rotation to...
animate
Left Move Rule
When all of the following
when left arrow key is pressed
if self position is X
move in direction
constrain self.rotation to...
animate
so on an so forth for the up and down arrow keys.
The constrain self.rotation, and the animate are redundant, and for that matter, I it seems an "if any" conditional would work better.
Something like this:
Group: if any: key press right, key press left, key press up, key press down)
Group do: (move in the direction arrow is pressed, constrain self.rotation, animate
But I seem to be placing the constrain self.rotation and the animate int he wrong spot because when I try to group them in a way that seems more efficient, things break.
Comments
If you want a behavior to function independently of a rule, just don't place it in a rule. But I suspect that's not what you're going for. If you want a behavior to function when any movement key is pressed, then you would do this:
When key right is down
change attribute self.moving (boolean) to true
Otherwise
change attribute self.moving to false
Do that for each of the four keys/direction. Then have a single rule:
When attribute self.moving is true
Constrain rotation
Animate
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User