Hey, I was wondering if anyone knew how to fix this code I was working on. It's in Action Script 2.0 and is in the time line.
Here is the code:
if (!Key.isDown(Key.DOWN) ) { IsCrouch = false } if (Key.isDown(Key.DOWN)) IsCrouch = true gotoAndStop("crouch" }else if (speed == 0) { gotoAndStop("idle" }
What it's suppose to do is when you press the down arrow it goes to the crouching animation called "crouch" and when you let go, it goes back to idle. Unfortunately it doesn't work. Please help if you can.
I would need to see more code that's interacting with the character control to figure this one out. Everything you have there looks fine, unless it's a syntax or naming error.
Yeah, I agree with plasma I don't see anything wrong, the problem is probably located somewhere else or you made a mistake somewhere. Or more likely don't fully understand the code so entire sections are probably wrong, because this is a relatively simple thing to do.
It works for me... Have you made sure to put this inside an onEnterFrame function? or a function called by an onEnterFrame function? If you don't then this bit of code will only be called on once at the beggining or even never at all. Also I'm not sure why you have quotation marks on "crouch" and "idle", if you have made variables called 'crouch' and 'idle' that hold integers of to hold frame numbers, then you don't need the quotation marks to refer to those variables.
onEnterFrame = function() { if (Key.isDown(Key.DOWN)) gravity = -jumpheight; gotoAndStop("crouch" gravity == 0 else if (!Key.isDown(Key.DOWN)) gotoAndStop("idle" }
Are you having problems with copy pasting? Because you always seem to miss out some vital parts. If you dont use an open brace after after an if statement it will only run the next line as part of the if statement and you wont be able to accompany it with an else. And else needs to follow a closing brace. What you might be trying to do is this;
You put two equals sign for gravity = 0, and that checks if gravity is equal to 0, it doesnt make gravity equal to 0. This piece of code makes no sense however, even though there should be no syntax errors here at all. You are setting gravity to equal -jumpheight and then to 0 shortly after, and then you don't have anyway to revert gravity to a normal value.