Republican31 Posted July 19, 2015 Share Posted July 19, 2015 Hi, I have a little problem. I am new to JavaScript, but I am trying to make an HTML5 game. I have done quite well so far I think, but there are a few issues that are stumping me. In this case, I can't find a way to end a JavaScript function from within another function. I just want a way to say:function game() {function move() { if(playerY <= 0){ gameOver(); game().end; return; }}function gameOver() {}If that makes any sense. Is there a way to do this? This is for a 72 Hour Game Jam, and it ends Sunday at 9:00 PM my time, and it's Saturday at 10 PM now. Quote Link to comment Share on other sites More sharing options...
AzraelTycka Posted July 24, 2015 Share Posted July 24, 2015 Hello, although late I'll just give an example how to do it, there is more ways how to achieve this. First of all I would put move and gameOver functions out of the game function local scope (although it's not necessary I advise you to do that if possible). Either way you can return from game function this way:function game(){ // some code if (move()) { gameOver(); return; }}function move(){ // some code return (playerY <= 0);}function gameOver(){ // some code} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.