Fire Dragon Posted February 23, 2006 Share Posted February 23, 2006 I have problem with confirm box what I should use on my textbased game.There is question and you can say OK or Cancel.My problem is,that if you answer "OK",you should continue to next alert example.And then continue to next and next...But if you answer "Cancel",you must get different alert and then program must direct you to new URL.However,now program gives after Cancel message my OK answer's continue messages,what I write outside confirm box's code,and after those messages it directes you to new URL.Sounds confusing,so here is my code: <script type="text/javascript">function gameover(){window.location="http://www.geocities.com/zelda_life/game_over.html"}alert("It is dark night.")var lahdetko=confirm("Would you go to out?")if (lahdetko==true){alert("Outside is cold,but it feels good.")}else{alert("Huge boulder crashed your house,and you die.")gameover()}var nimi=prompt("What's your name?Asks stranger.","")if (nimi!=null && nimi!=""){alert("" + nimi + "...Interesting...")}</script> Like you can see,I tried function,but it gives same problem than just writing location after "Cancel alert".What I should to do,that it won't transfer player to prompt after "Cancel alert"?I know that I can write all alerts inside confirm,but my code probably have many many confirms and others,so I would like to write other code outside confirm.Thanks.I don't know do you understand anything,but I hope so! Link to comment Share on other sites More sharing options...
Pollux Posted February 23, 2006 Share Posted February 23, 2006 Put the game play inside a function, and if you don't want that function to continue running then just return from the function, e.g.: function gameover(){ window.location="http://www.geocities.com/zelda_life/game_over.html";}function play(){ alert("It is dark night."); if (!confirm("Would you go to out?")){ alert("Huge boulder crashed your house,and you die."); gameover(); return; } alert("Outside is cold,but it feels good."); var nimi=prompt("What's your name?Asks stranger.",""); if (nimi!=null && nimi!=""){ alert("" + nimi + "...Interesting..."); }} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now