I have a keypress script which temporarily overrides the normal arrow key movement allowing the hero to turn to face a direction before proceeding to walk in that direction. This code seems to work fine asides from one thing. When the hero is moving in one direction, say down, and I also click the left key (which should make the hero walk left), the hero continues to walk down.
I want to know if there is any way to make the latest arrow key press trump the old arrow key press. The way my code is now certain arrow keys tend to trump others but I can't seem to understand why that's so. Here's my keypress script (Note: the timers are just for carrying out a wait so when a direction is changed the character turns to the new direction momentarily, this timer does not apply during the case in which multiple arrow keys are being pressed):
Code: Select all
### Right Arrow ###
if(keyval(key:Right) > 1) then(
if(hero direction == right) then(
#Do nothing, default movement resumes
) else (
if((keyval(key:Left) == 0) && (keyval(key:Up) == 0) && (keyval(key:Down) == 0)) then(
suspend player
set hero direction(0,right)
changingDirectionR := 1
DirectionR Timer
)
)
)
### Left Arrow ###
if(keyval(key:Left) > 1) then(
if(hero direction == left) then(
#Do nothing, default movement resumes
) else (
if((keyval(key:Right) == 0) && (keyval(key:Up) == 0) && (keyval(key:Down) == 0)) then(
suspend player
set hero direction(0,left)
changingDirectionL := 1
DirectionL Timer
)
)
)
### Up Arrow ###
if(keyval(key:Up) > 1) then(
if(hero direction == up) then(
#Do nothing, default movement resumes
) else (
if((keyval(key:Left) == 0) && (keyval(key:Right) == 0) && (keyval(key:Down) == 0)) then(
suspend player
set hero direction(0,up)
changingDirectionU := 1
DirectionU Timer
)
)
)
### Down Arrow ###
if(keyval(key:Down) > 1) then(
if(hero direction == down) then(
#Do nothing, default movement resumes
) else (
if((keyval(key:Left) == 0) && (keyval(key:Up) == 0) && (keyval(key:Right) == 0)) then(
suspend player
set hero direction(0,down)
changingDirectionD := 1
DirectionD Timer
)
)
)