Jump to content
Sign in to follow this  
Matu

My Game

Recommended Posts

Matu

Hi everyone, Ive just started using AUTOIT, and written a script for texted based game, using GUI's.

my problem is, since there's no GOTO command, I cant make my program re-start from the begining.

if anyone can help, please e-mail me, or edit the script posted

thanks

Matu

Share this post


Link to post
Share on other sites
themax90

Start()

Func Start()

; Your Script

EndFunc

Share this post


Link to post
Share on other sites
MHz

This script restarts by using a varaible to keep count and a function to calculate and update the data in the label

#include <guiconstants.au3>
Global $button1, $counter = 0, $data1, $final, $form1, $label_1, $msg, $sum, $total

$form1 = GUICreate("GAME", 383, 208, 202, 131)
GUISetBkColor(0xffff00)
GUISetState(@SW_SHOW)
GUICtrlCreateLabel("THE MIND GAME", 70, 24, 261, 41)
GUICtrlSetFont(-1, 24, 400, 0, "ms sans serif")
$label_1 = GUICtrlCreateLabel("", 70, 100, 260, 21, 0x1000)
$button1 = GUICtrlCreateButton("OK", 130, 150, 130, 20)
GUICtrlSetColor(-1, 0xff00ff)
GUICtrlSetBkColor(-1, 0x000000)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button1
            PlayFunction()
    EndSelect
WEnd

Exit

Func PlayFunction()
    GUICtrlSetState($button1, $GUI_DISABLE)
    Switch $counter
        Case 0
            $data1 = " THINK OF ANY NUMBER BETWEEN 10 - 1000"
        Case 1
            $data1 = " MULTIPLY THAT NUMBER BY 2"
        Case 2
            $total = (Random(1000))
            $final = (Round($total))
            If $final < 10 Then $final = 10
            $data1 = " NOW ADD    " & $final
        Case 3
            $data1 = " DIVIDE THAT NUMBER BY 2"
        Case 4
            $data1 = " SUBTRACT THAT NUMBER YOU THOUGHT OF"
        Case 5
            $sum = $final / 2
            $data1 = " YOUR FINAL ANSWER SHOULD BE  " & $sum
            $counter = 0
            GUICtrlSetData($label_1, $data1)
            GUICtrlSetState($button1, $GUI_ENABLE)
            Return
    EndSwitch
    $counter += 1
    GUICtrlSetData($label_1, $data1)
    GUICtrlSetState($button1, $GUI_ENABLE)
EndFunc

:P

Share this post


Link to post
Share on other sites
MHz

That line is using Switch which is available in the AutoIt v3.2.0.1 public release. Perhaps you are still using the older 3.1.1 version?

Have a look at the download page if needed to update your AutoIt version.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.