Jump to content
Sign in to follow this  
Hok

Random Question

Recommended Posts

Hok

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.10.0

Author: Henry

OS: WinXP

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstants.au3>

$Random=Random(1,100,1)

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\hdixon\Desktop\AUTOIT PROGRAMMING\KODA\Guess My Number.kxf

$Form1 = GUICreate("Guess my Number", 401, 230, 193, 125)

GUISetBkColor(0xFFFFFF)

$Input1 = GUICtrlCreateInput("", 0, 56, 393, 21)

GUICtrlSetTip(-1, "Enter your guess here")

$Label1 = GUICtrlCreateLabel("Enter Your Guess Here:", 0, 0, 352, 48)

GUICtrlSetFont(-1, 26, 800, 0, "Adobe Garamond Pro")

$Button1 = GUICtrlCreateButton("Guess!", 0, 88, 195, 73, 0)

GUICtrlSetFont(-1, 22, 800, 0, "Waltography MV")

$Button2 = GUICtrlCreateButton("Credits", 200, 88, 193, 73, 0)

GUICtrlSetFont(-1, 18, 800, 0, "Walt Disney Script")

$Label2 = GUICtrlCreateLabel("Status:", 8, 168, 376, 48)

GUICtrlSetFont(-1, 15, 800, 0, "Toxica")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button2

MsgBox(0, "Credits", "Scripting: Henry Dixon (^^)")

Case $Button1

Test()

EndSwitch

WEnd

Func Test()

$Counter=0

$Guess=GUICtrlRead($input1)

If $guess< $Random Then

$Label2 = GUICtrlCreateLabel("Status: The Number is Lower!", 8, 168, 376, 48)

GUICtrlSetFont(-1, 15, 800, 0, "Toxica")

$Counter=$Counter+1

EndIf

If $guess> $Random Then

$Label2 = GUICtrlCreateLabel("Status: The Number is Higher!", 8, 168, 376, 48)

GUICtrlSetFont(-1, 15, 800, 0, "Toxica")

$Counter=$Counter+1

EndIf

If $guess=$Random Then

$Counter=$Counter+1

$Label2 = GUICtrlCreateLabel("Nice! You got it! It took you " &$counter &" tries", 8, 168, 376, 48)

GUICtrlSetFont(-1, 15, 800, 0, "Toxica")

EndIf

EndFunc

Is there any GUILabelKill command or anything to kill the label when I am done with it??? I try typing 100 and it says Status: The number is lower! but then I type in 1 and press the button and it says the same thing...

Share this post


Link to post
Share on other sites
newbiescripter

Use:

GUICtrlSetData ( controlID, data [, default] )

EDIT: You should change the labels:

If $guess < $Random Then
$Label2 = GUICtrlCreateLabel("Status: The Number is Higher!", 8, 168, 376, 48)

If $guess > $Random Then
$Label2 = GUICtrlCreateLabel("Status: The Number is Lower!", 8, 168, 376, 48)

Or els it will not be right.. try type in 1 and see that is says that the number is lower which is wrong :)

EDIT:

#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.10.0
Author: Henry
OS: WinXP

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstants.au3>
$Random=Random(1,100,1)

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\hdixon\Desktop\AUTOIT PROGRAMMING\KODA\Guess My Number.kxf
$Form1 = GUICreate("Guess my Number", 401, 230, 193, 125)
GUISetBkColor(0xFFFFFF)
$Input1 = GUICtrlCreateInput("", 0, 56, 393, 21)
GUICtrlSetTip(-1, "Enter your guess here")
$Label1 = GUICtrlCreateLabel("Enter Your Guess Here:", 0, 0, 352, 48)
GUICtrlSetFont(-1, 26, 800, 0, "Adobe Garamond Pro")
$Button1 = GUICtrlCreateButton("Guess!", 0, 88, 195, 73, 0)
GUICtrlSetFont(-1, 22, 800, 0, "Waltography MV")
$Button2 = GUICtrlCreateButton("Credits", 200, 88, 193, 73, 0)
GUICtrlSetFont(-1, 18, 800, 0, "Walt Disney Script")
$Label2 = GUICtrlCreateLabel("Status:", 8, 168, 376, 48)
GUICtrlSetFont(-1, 15, 800, 0, "Toxica")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$Counter=1

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button2
            MsgBox(0, "Credits", "Scripting: Henry Dixon (^^)")
        Case $Button1
            Test()
            sleep(1500)
            GUICtrlSetData($Label2,"Status: Try guessing a new number!")
            Sleep(1500)
            GUICtrlSetData($Label2,"Status:")
    EndSwitch
WEnd


Func Test()
$Guess=GUICtrlRead($input1)

Select
    Case ($guess > $Random)
        $Label2 = GUICtrlCreateLabel("Status: The Number is Lower!", 8, 168, 376, 48)
        GUICtrlSetFont(-1, 15, 800, 0, "Toxica")
        $Counter=$Counter+1
    
    Case ($guess < $Random)
        $Label2 = GUICtrlCreateLabel("Status: The Number is Higher!", 8, 168, 376, 48)
        GUICtrlSetFont(-1, 15, 800, 0, "Toxica")
        $Counter=$Counter+1
        
    Case ($guess == $Random)
        $Label2 = GUICtrlCreateLabel("Nice! You got it! It took you " &$counter &" tries", 8, 168, 376, 48)
        GUICtrlSetFont(-1, 15, 800, 0, "Toxica")
        $Counter=$Counter+1
        Sleep(2000)
EndSelect
EndFunc; Test()

The above is a little quick example, but you can do it in a smarter way :(

Edited by newbiescripter

Share this post


Link to post
Share on other sites
Hiyoal

To Kill or "destroy" a control, use GUICtrlDelete(), or else, use GUICtrlSetData to set it to "".

Also, Globally declare $Counter=0 at the start of the script to not limit the variable in the control. It wasnt working properly before.

Hiyoal

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×