PDA

View Full Version : Function help.... AGAIN



JoMan
October 6th, 2004, 11:28 PM
Ok, so far, the jumping is working, but now the other function wont work! I have tried everything in my power to fix this, but it wont work. If any one has any suggestions or help, it would be very helpful. Thanks. Oh, and here is my code:


Scrolling();
Moving();
StartGame();
Dying();
function StartGame() {
move = true;
xspeed = 2;
vel_y = 0;
jumping = false;
_root.onEnterFrame = Moving;
}
function Moving() {
if (Key.isDown(Key.RIGHT) && move) {
hero.gotoAndStop("run");
} else if (Key.isDown(Key.LEFT) && move) {
hero.gotoAndStop("run");
} else {
hero.gotoAndStop("edle");
}
if (Key.isDown(Key.UP) && !jumping) {
hero.gotoAndStop("jump");
vel_y = 20;
jumping = true;
}
if (jumping == true) {
vel_y -= 1;
if (vel_y<=-20) {
vel_y = -20;
}
hero._y -= vel_y;
}
}
function Dying() {
if (hero.sword.hitTest(enemy)) {
enemy.gotoAndStop("dead");
score += 5;
}
}





peace

Dr Warm
October 6th, 2004, 11:34 PM
ok i so is moving working or not?
i wouldn't have _root.onEnterFrame inside a function, rather
_root.onEnterFrame = function() {
Moving; //u don't always need to have () after, i can't remember when u want
//it and when u don't experiment with it
}
also if that doesn't work have u functions as
Moving = function(){};
etc again i always do it like this and i'm not sure what difference it is or anything.
BTW this is all in the main time line right?

JoMan
October 7th, 2004, 08:50 AM
ok i so is moving working or not?
i wouldn't have _root.onEnterFrame inside a function, rather
_root.onEnterFrame = function() {
Moving; //u don't always need to have () after, i can't remember when u want
//it and when u don't experiment with it
}
also if that doesn't work have u functions as
Moving = function(){};
etc again i always do it like this and i'm not sure what difference it is or anything.
BTW this is all in the main time line right?
Oh, Im sorry, I forgot to specify. The Dying() isnt working.

Dr Warm
October 7th, 2004, 09:27 AM
u're not calling dying every frame, just once at the beginning
i suggest having
_root.onEnterFrame = function(){
moving();
dying();
//or try
moving;
dying;
}
that might solve it?

JoMan
October 7th, 2004, 01:12 PM
Nope, didn't work. Any other suggestions?

JoMan
October 7th, 2004, 06:12 PM
Wait! I found the problem! It was because I needed a Dying(); in the end of the Movement function. Geez, sometimes I can be a real moron :crazy:. Thanks for your help, Dr. Warm :thumb:




peace

Dr Warm
October 7th, 2004, 08:20 PM
thats cool, nice to see ur moving away from the onClipEvents!

JoMan
October 7th, 2004, 11:43 PM
Yeah :D. onClipEvents were commonly used "back in the day" in FlashKit. I find functions to be much more efficient and more fun to use :P.




peace