PDA

View Full Version : HELP!!! simple actionscripting problem



yoshijumper
03-31-2010, 01:42 PM
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
03-31-2010, 09:15 PM
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
04-01-2010, 07:05 AM
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
04-02-2010, 08:09 PM
....

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
04-04-2010, 12:13 PM
wait, what's the problem? sorry your wording is kinda confusing

yoshijumper
04-05-2010, 11:00 AM
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...