Jump to content

How To End A Specific Function From Another Function


 Share

Recommended Posts

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.

Link to comment
Share on other sites

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}
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...