quick_sliver007 Posted April 16, 2005 Share Posted April 16, 2005 I am in the process of making a hangman game and I have gotten to a critical part and got stuck. Here is the code.....expandcollapse popup#include <GuiConstants.au3> #include <Array.au3> $Gui = GuiCreate("Hangman", 299, 387,(@DesktopWidth-299)/2, (@DesktopHeight-387)/2 ) $Pic = GuiCtrlCreatePic("1.bmp", 10, 20, 280, 260) GuiCtrlCreateLabel("Used Letters:", 10, 320, 65, 20) $Label_Used_Letters = GUICtrlCreateLabel("",72,320,150,20) $Input = GuiCtrlCreateInput("", 10, 350, 130, 20) GUICtrlSetLimit($input,1) $Button_Enter = GuiCtrlCreateButton("Enter", 160, 350, 130, 20) _setletters() GuiSetState(@SW_SHOW,$GUI) func _enter() ControlClick("Hangman","Enter",7) EndFunc HotKeySet("{ENTER}","_enter") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; func _setletters() Global $random = Random(1,25) Global $string = FileReadLine("wordlist.txt",3); using the 3rd word(seattle) for testing Global $stringsplit = StringSplit($string,"") Global $labels[20] Global $c For $c = 1 To $stringsplit[0] $labels[$c] = GUICtrlCreateLabel("_", $c * 10, 290, 10, 20) Next Return $stringsplit[0] EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_Enter Local $Read_Input = GUICtrlRead($Input) Global $Count = 0 Do $Count = $Count + 1 Global $StringInStr = StringInStr($String,$Read_Input,0,$count) If $read_input = "" Then ElseIf $StringInStr = 0 Then $Read_Used = GUICtrlRead($Label_Used_Letters) GUICtrlSetData($Label_Used_Letters,$Read_input&$Read_Used) Else GUICtrlSetData($labels[$StringInStr],$read_input) EndIf Until $count = $stringsplit[0] ;If $stringinstr = @error Then ;sgBox(0,$stringinstr,"") ;EndIf GUICtrlSetData($input,"") GUICtrlSetState($input,$Gui_focus) EndSelect WEnd Exit Here is the problem areaCase $msg = $Button_Enter Local $Read_Input = GUICtrlRead($Input) Global $Count = 0 Do $Count = $Count + 1 Global $StringInStr = StringInStr($String,$Read_Input,0,$count) If $read_input = "" Then ElseIf $StringInStr = 0 Then $Read_Used = GUICtrlRead($Label_Used_Letters) GUICtrlSetData($Label_Used_Letters,$Read_input&$Read_Used) Else GUICtrlSetData($labels[$StringInStr],$read_input) EndIf Until $count = $stringsplit[0] The string that it is reading from the file is "seattle". String has 7 letters and "e" and "t" are used more then one time. This is the problem, $count is going past the number of letters in the word. I need to find a different way to check all locations in the string "seattle". If I remove the Do Until Statement like Case $msg = $Button_Enter Local $Read_Input = GUICtrlRead($Input) Global $Count = 0 $Count = $Count + 1 Global $StringInStr = StringInStr($String,$Read_Input,0,$count) If $read_input = "" Then ElseIf $StringInStr = 0 Then $Read_Used = GUICtrlRead($Label_Used_Letters) GUICtrlSetData($Label_Used_Letters,$Read_input&$Read_Used) Else GUICtrlSetData($labels[$StringInStr],$read_input) EndIf ;If $stringinstr = @error Then ;sgBox(0,$stringinstr,"") ;EndIf GUICtrlSetData($input,"") GUICtrlSetState($input,$Gui_focus) It does ever thing right except check all locations in the string"seattle". But with the Do Until loop it puts all of the letters in the $Label_Used_Letter label and does it more then one time like 5 of the letters in a row. I want it to do like it does without the do loop and check all of the letters in the string. Also I want to be able to trap when $stringinstr = 0. Like in the msgbox I edited out. If anyone can help, I will be very thankful. . Link to comment Share on other sites More sharing options...
steveR Posted April 16, 2005 Share Posted April 16, 2005 (edited) Fixed it some: expandcollapse popup#include <GuiConstants.au3> #include <Array.au3> $Gui = GUICreate("Hangman", 299, 387, (@DesktopWidth - 299) / 2, (@DesktopHeight - 387) / 2) $Pic = GUICtrlCreatePic("1.bmp", 10, 20, 280, 260) GUICtrlCreateLabel("Used Letters:", 10, 320, 65, 20) $Label_Used_Letters = GUICtrlCreateLabel("", 72, 320, 150, 20) $Input = GUICtrlCreateInput("", 10, 350, 130, 20) GUICtrlSetLimit($Input, 1) $Button_Enter = GUICtrlCreateButton("Enter", 160, 350, 130, 20) _setletters() GUISetState(@SW_SHOW, $Gui) Func _enter() ControlClick("Hangman", "Enter", 7) EndFunc ;==>_enter HotKeySet("{ENTER}", "_enter") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _setletters() Global $random = Random(1, 25) Global $string = "seattle"; using the 3rd word(seattle) for testing Global $stringsplit = StringSplit($string, "") Global $labels[20] Global $c For $c = 1 To $stringsplit[0] $labels[$c] = GUICtrlCreateLabel("_", $c * 10, 290, 10, 20) Next Return $stringsplit[0] EndFunc ;==>_setletters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $lettersUsed = "" While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_Enter If GUICtrlRead($Input) <> "" Then Local $Read_Input = GUICtrlRead($Input) If Not _isLetterUsed() Then Global $Count = 0 Do $Count = $Count + 1 Global $StringInStr = StringInStr($string, $Read_Input, 0, $Count) GUICtrlSetData($labels[$StringInStr], $Read_Input) Until $Count = $stringsplit[0] EndIf GUICtrlSetData($Input, "") GUICtrlSetState($Input, $Gui_focus) Else GUICtrlSetState($Input, $Gui_focus) EndIf EndSelect WEnd Exit Func _isLetterUsed() If StringInStr($lettersUsed, $Read_Input) Then MsgBox(0, "", "letter used") Return 1 Else $lettersUsed = $lettersUsed & $Read_Input GUICtrlSetData($Label_Used_Letters, $lettersUsed) EndIf EndFunc ;==>_isLetterUsed Edited April 16, 2005 by steveR AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass. Link to comment Share on other sites More sharing options...
quick_sliver007 Posted April 16, 2005 Author Share Posted April 16, 2005 Fixed it some:expandcollapse popup#include <GuiConstants.au3> #include <Array.au3> $Gui = GUICreate("Hangman", 299, 387, (@DesktopWidth - 299) / 2, (@DesktopHeight - 387) / 2) $Pic = GUICtrlCreatePic("1.bmp", 10, 20, 280, 260) GUICtrlCreateLabel("Used Letters:", 10, 320, 65, 20) $Label_Used_Letters = GUICtrlCreateLabel("", 72, 320, 150, 20) $Input = GUICtrlCreateInput("", 10, 350, 130, 20) GUICtrlSetLimit($Input, 1) $Button_Enter = GUICtrlCreateButton("Enter", 160, 350, 130, 20) _setletters() GUISetState(@SW_SHOW, $Gui) Func _enter() ControlClick("Hangman", "Enter", 7) EndFunc ;==>_enter HotKeySet("{ENTER}", "_enter") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _setletters() Global $random = Random(1, 25) Global $string = "seattle"; using the 3rd word(seattle) for testing Global $stringsplit = StringSplit($string, "") Global $labels[20] Global $c For $c = 1 To $stringsplit[0] $labels[$c] = GUICtrlCreateLabel("_", $c * 10, 290, 10, 20) Next Return $stringsplit[0] EndFunc ;==>_setletters ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $lettersUsed = "" While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $Button_Enter If GUICtrlRead($Input) <> "" Then Local $Read_Input = GUICtrlRead($Input) If Not _isLetterUsed() Then Global $Count = 0 Do $Count = $Count + 1 Global $StringInStr = StringInStr($string, $Read_Input, 0, $Count) GUICtrlSetData($labels[$StringInStr], $Read_Input) Until $Count = $stringsplit[0] EndIf GUICtrlSetData($Input, "") GUICtrlSetState($Input, $Gui_focus) Else GUICtrlSetState($Input, $Gui_focus) EndIf EndSelect WEnd Exit Func _isLetterUsed() If StringInStr($lettersUsed, $Read_Input) Then MsgBox(0, "", "letter used") Return 1 Else $lettersUsed = $lettersUsed & $Read_Input GUICtrlSetData($Label_Used_Letters, $lettersUsed) EndIf EndFunc ;==>_isLetterUsed<{POST_SNAPBACK}>Thank you veryyy much. That helps alot. . Link to comment Share on other sites More sharing options...
zcoacoaz Posted April 19, 2005 Share Posted April 19, 2005 let's hope your game can be in the Scripts and Scraps section soon [font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font] Link to comment Share on other sites More sharing options...
quick_sliver007 Posted April 19, 2005 Author Share Posted April 19, 2005 let's hope your game can be in the Scripts and Scraps section soon <{POST_SNAPBACK}>I just got though all the hard part. Things are looking good. Now I am into the tedious part. When I get it done I plan on putting it there after I go over kill on the notes for all the newbies. . 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