00:00
00:00
Newgrounds Background Image Theme
Upgrade Your Account!

HO HO HOPE you become a Newgrounds Supporter this year!

We're working hard to give you the best site possible, but we have bills to pay and community support is vital to keep things going and growing. Thank you for considering!

Become a Supporter so NG can see another Christmas!

finishing a function

382 Views | 1 Reply
New Topic Respond to this Topic

finishing a function 2006-08-09 22:10:57


Hey guys, i need a little help on this. Im making a fighting game and i have made a few moves such as jumps, kicks, and punches. they are all working perfectly and everything. But my one problem is, say you jump then hit jump again it will stop mid jump and start a new one. i would like to know of a code that would make it complete a process regardless of what other buttons it is pushing besides left and right. so if im punching i dont want it to be able to stop mid-stream and begin to kick.

Any Help would be great thanks alot guys.

Response to finishing a function 2006-08-09 22:22:49


Your problem might be the way youre coding it.

Say, if youre using this kind of logic

if(//press space){
//stuff
}else if(//more stuff){
//more stuff;
} else if etc

You'll get that error. Because it runs like this:

It checks for the first condition. If its true, then it executes. If its false, it goes to the next one until it finds one that is true. So, if you have your punching code above the jumping one, which ones executed first?

Punching. Right.

So, if it first runs the jumping code, then you press the punch key, it will check for the punching key being true, which will execute THAT action. Nullifying your previous action.

So its either two of these options:

reorder the code,
or use different logic.

instead of using else if's, just use a lot of ifs. A lot more messy, but still.

I just hope that's your problem.

long post.