HELP!!! simple actionscripting problem

Started by: yoshijumper | Replies: 5 | Views: 749

yoshijumper

Posts: 86
Joined: Mar 2010
Rep: 10

View Profile
Mar 31, 2010 7:42 PM #561640
hey guys, im tryin to do some scriptin for a simple game and i came across a problem, if anybody has a solution or knos where someone can give me a solution plz lemme kno....

so heres the problem...i have a stick guy for my character, i can get him to walk easily and jump if i wanted but i cant get him to run...i have just arrow keys for walking and i wanted to have arrow+shift to run...or any other simple key to go with arrow... ill post under here the general part of my script that i need help with.....

if(Key.isDown(Key.RIGHT)){
this._x += walkspeed;
this._xscale = 100;
gotoAndStop(2);
}
if(Key.isDown(Key.LEFT)){
this._x -= walkspeed;
this._xscale = -100;
gotoAndStop(2);
}
if(Key.isDown(Key.RIGHT) and (Key.isDown(Key.SHIFT))){
this._x += runspeed;
this._xscale = 100;
gotoAndPlay(3);
}
if(Key.isDown(Key.LEFT) and (Key.isDown(Key.SHIFT))){
this._x -= runspeed;
this._xscale = -100;
gotoAndPlay(3);
}
if(!Key.isDown(Key.RIGHT) and (!Key.isDown(Key.LEFT))){
gotoAndStop(1);
}

so can anyone help me?!?!?!?!? plz lemme kno what noobish thing ive done this time lolz :D

im sure itz sumthin simple...im jst a noob
CGIllusion
2

Posts: 617
Joined: Aug 2005
Rep: 21

View Profile
Apr 1, 2010 3:15 AM #561851
Use "else if" statements.

if(Key.isDown(Key.RIGHT) and (Key.isDown(Key.SHIFT))){
this._x += runspeed;
this._xscale = 100;
gotoAndPlay(3);
}
else if(Key.isDown(Key.RIGHT)){
this._x += walkspeed;
this._xscale = 100;
gotoAndStop(2);
}

This will first check if right and shift are both down at the same time, and if not it will check if right is pressed. If you use if statements only you may override some intended actions by your stick char.
yoshijumper

Posts: 86
Joined: Mar 2010
Rep: 10

View Profile
Apr 1, 2010 1:05 PM #561990
Thankx man!! really helped me, so because i only used if statements was the problem...what if i wanted a different animation to show durning like a crouch or roll, or whatever. ive never been able to play more than the one at a time, walk/run left and right...

if (Key.isDown(Key.SPACE)){
gotoAndStop(4);
crouching = true;
}

how would i get him to stay into crouch until a different button is pressed...i dont care about that as much, i just want to have an animation for running, walking, jump, crouch...i have all the ani.s but i cant get them to play..save walk and run, they play on key....
yoshijumper

Posts: 86
Joined: Mar 2010
Rep: 10

View Profile
Apr 3, 2010 2:09 AM #562898
....

if (Key.isDown(Key.SPACE)){
gotoAndStop(4);
crouching = true;
}

....this doesnt work by the way, i was asking if you knew how to make this work......
doc

Posts: 1,127
Joined: Jan 2009
Rep: 10

View Profile
Apr 4, 2010 6:13 PM #563807
wait, what's the problem? sorry your wording is kinda confusing
yoshijumper

Posts: 86
Joined: Mar 2010
Rep: 10

View Profile
Apr 5, 2010 5:00 PM #564227
i can only get the running/walking to play...i cant get jumping, crouching, or any other animation to play. not just the current game im working on, but not any i have ever tried. i got walking to work by using arrow keys. then i got running to work by using an else if statement. but now i cant get any other animation to play on key...