Tekki Posted July 15, 2009 Share Posted July 15, 2009 (edited) I feel really stupid because I feel that this shouldn't be difficult. I just can't figure it out >.<I have a simple "Guess My Number" game that I am working on. A.T.M. it is VERY simple, I just can't figure out how to go back to the main func if you click Yes.expandcollapse popup$start = MsgBox(4, "Hey there!", "Would you like to play my Random Guess Game?") If $start = 6 Then Main() ElseIf $start = 7 Then Exit EndIf Func Main() $number = Random(1,10,1) ; Generates the number that you must guess. $guess = Int(InputBox("Guess my number","Guess my number. It is 1 - 10" & @CRLF & "Type it below.")) If @error = 1 Then Exit ElseIf $guess > 10 Or $guess < 1 Then MsgBox(0,"Error", "You must only type in the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10... Try again") Main() EndIf If $guess = $number Then $msg = "You win!" Else $msg = "Sorry, You lost." EndIf MsgBox(0,"Results", $msg & " Your number was " & $guess & " and my number was " & $number) ; Find out if you won or lost! $again = MsgBox(4, "Play Again", "Would you like to try again?") ;4 = Yes/No button If $again = 6 Then ; 6 = Yes button Main() ElseIf $again = 7 Then ; 7 = No button MsgBox(0,"Thanks","Thanks for playing (made by John)") Exit EndIf EndFuncThat is with all my failed attempts removed. LOL... okay well if you have any suggestions PLEASE post them.EDIT: Posted new code that works - only one bug. The cancel button no longer works and I can't figure it out Edited July 15, 2009 by Tekki If you intend to use Sarcasm you must this sticker!!![size="1"][sub]pic made by manadar[/sub][/size] Link to comment Share on other sites More sharing options...
UnknownWarrior Posted July 15, 2009 Share Posted July 15, 2009 (edited) $again = MsgBox(4, "Yo", "Would you like to try again?") ;4 = Yes/No button If $again = 6 Then ; 6 = Yes button Main() ElseIf $again = 7 Then ; 7 = (You take a guess xD) Exit EndIf There you go sir Edited July 15, 2009 by UnknownWarrior Link to comment Share on other sites More sharing options...
Tekki Posted July 15, 2009 Author Share Posted July 15, 2009 (edited) Thank you very much. . Edit: It seems it only asks once. Lol. How would you make it ask every time until you say no. Edited July 15, 2009 by Tekki If you intend to use Sarcasm you must this sticker!!![size="1"][sub]pic made by manadar[/sub][/size] Link to comment Share on other sites More sharing options...
UnknownWarrior Posted July 15, 2009 Share Posted July 15, 2009 (edited) Thank you very much. . Edit: It seems it only asks once. Lol. How would you make it ask every time until you say no. I'll get back to you in 2 minutes (I'll just edit this post)... Must go do something real fast. $start = MsgBox(4, "Hey there!", "Would you like to play my Random Guess Game?") If $start = 6 Then Main() ElseIf $start = 7 Then Exit EndIf Func Main() $number = Random(1,10,1) ; Generates the number that you must guess. $guess = InputBox("Guess my number","Guess my number. It is 1 - 10" & @CRLF & " Type it below.") ; Ask's for your guess If @error = 1 Then Exit ElseIf $guess > 10 Or $guess < 1 Then MsgBox(0,"Oops", "You MUST only type in the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10... Try again") Main() EndIf If $guess = $number Then $msg = "You win!" Else $msg = "Sorry, You lost." EndIf MsgBox(0,"Results", $msg & " Your number was " & $guess & " and my number was " & $number) ; Find out if you won or lost! $again = MsgBox(4, "Yo", "Would you like to try again?") ;4 = Yes/No button If $again = 6 Then ; 6 = Yes button Main() ElseIf $again = 7 Then ; 7 = (You take a guess xD) Exit EndIf EndFunc I added a few things... The main one was: ElseIf $guess > 10 Or $guess < 1 Then MsgBox(0,"Oops", "You MUST only type in the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10... Try again") Main() EndIf That way if they type in ANYTHING other than 1-10, it will re-do it. That also means it will re-do if they type in any letters, etc. Edited July 15, 2009 by UnknownWarrior Link to comment Share on other sites More sharing options...
Tekki Posted July 15, 2009 Author Share Posted July 15, 2009 (edited) I forgot to ask - how would I make it accept only integers (not needed - I can figure out on my own sometime) LOL EDIT: Thanks for the answer Edited July 15, 2009 by Tekki If you intend to use Sarcasm you must this sticker!!![size="1"][sub]pic made by manadar[/sub][/size] Link to comment Share on other sites More sharing options...
UnknownWarrior Posted July 15, 2009 Share Posted July 15, 2009 (edited) I forgot to ask - how would I make it accept only integers (not needed - I can figure out on my own sometime) LOL $guess = Int(InputBox("Guess my number","Guess my number. It is 1 - 10" & @CRLF & " Type it below.")) Edit: Not really your specific question... Your question I think is what you meant is what I posted up above... This one makes it an actual INTEGER... Meaning if they type in 1.2 it would take their guess as just 1. Edited July 15, 2009 by UnknownWarrior Link to comment Share on other sites More sharing options...
Tekki Posted July 15, 2009 Author Share Posted July 15, 2009 Last issue then I'm done LOL... ... When you click Cancel on inputbox. It brings up the error screen of an incorrect number (like a letter or number 11+) If you intend to use Sarcasm you must this sticker!!![size="1"][sub]pic made by manadar[/sub][/size] Link to comment Share on other sites More sharing options...
UnknownWarrior Posted July 15, 2009 Share Posted July 15, 2009 Well... I've been working on it for like 5 minutes now and its starting to piss me off xD... I'm really not sure why the @error is going... No matter how I change up the If statements, it just will not execute that code when there is an @error. Garr... Idk, its probably some noob thing I'm not seeing, but I just cannot get it to work. The way I run it through my head... 'If cancel is pushed, go to: If @error Then Exit' But it's not doing what it should be doing ><. Link to comment Share on other sites More sharing options...
Tekki Posted July 15, 2009 Author Share Posted July 15, 2009 Well... I've been working on it for like 5 minutes now and its starting to piss me off xD... I'm really not sure why the @error is going... No matter how I change up the If statements, it just will not execute that code when there is an @error.Garr... Idk, its probably some noob thing I'm not seeing, but I just cannot get it to work. The way I run it through my head... 'If cancel is pushed, go to: If @error Then Exit'But it's not doing what it should be doing ><.Yeah I see your code and I think "This WILL work..." because error level 1 = pressing CANCEL. anything else (ie: wrong character) would be the elseif part. If you intend to use Sarcasm you must this sticker!!![size="1"][sub]pic made by manadar[/sub][/size] 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