Jump to content

Im having problem with my script.


AntiBNI
 Share

Recommended Posts

Sorry for making such many questions but im learning programing and every 1 learns with errors xD.

heres the thing im making a GUI script and when i try to loop the script.

Heres my full script

#include <GUIConstants.au3> 
#NoTrayIcon 
GUICreate ("Testthing",450,280) 
$button1=GUICtrlCreateButton ("Start",1,68,445,30) 
GUICtrlSetTip ($button1,"Start","Start",0,1) 
$button3 = GUICtrlCreateButton ("Exit",400,20,40,40) 
GUICtrlSetTip ($button3,"Stop and Exit","Exit",0,1) 
GUICtrlCreateLabel ("To Pause the script Press Pause",10,1) 
GUICtrlCreateLabel ("To Exit Press Esc",10,15) 
GUICtrlCreateGroup ("Loot for",10,29,145,40) 
$time=GUICtrlCreateInput ("Time in Milliseconds",14,43,135,20) 
GUICtrlSetTip ($time,"Type in milliseconds how long you want to bot. To get the time 1sec= 1000 milliseconds 1000 1min= 60000 1 Hour= 3600000, 7200000= 2Hours and so on.","Time in Miliseconds",0,1) 
GUISetBkColor (0xEFFFFFF) 
$pic = GUICtrlCreatePic("",0,100,450,180) 
GUICtrlSetImage($pic, @ScriptDir & "\mainbg.jpg") 
GUISetState () 
Global $Paused 
Hotkeyset ("{Pause}","Pause") 
Hotkeyset ("{Esc}","Terminate") 
Func Pause () 
$Paused = NOT $Paused 
While $Paused 
Sleep (100) 
ToolTip ("Paused",0,0) 
WEnd 
ToolTip ("") 
EndFunc 
Func Terminate () 
Exit 0 
EndFunc 
While 1 
   $msg = GUIGetMsg() 
   Select 
       Case $msg = $GUI_EVENT_CLOSE 
           ExitLoop 
$i = 1
Do  ;This is the part that when i start the bot gives me an error saying "Case" statement with no matching "select" or "switch" statement. its like blocking the Select stame ment, i donno what to do.
Case $msg = $button1 
ToolTip ("Please go to Notepad Window to Begin") 
WinWaitActive ("NotePad","") 
ToolTip ("") 
Send ("f") 
Sleep (1000) 
Send ("f") 
Sleep (1000) 
   Case $msg = $button3 
   Exit 
  Case $msg = $time 
   WinWaitActive ("NotePad","") 
   Sleep (GUICtrlRead ($time)) 
   WinWaitClose ("NotePad","") 
   Run ("Notepad.exe") 
Sleep (2000) 
Send ("time has finished.",$lvl) 
Send ("{Enter}") 
Send ("ThankYou for using the script.") 
Send ("{Esc}") 
EndSelect 
WEnd 
$i = $i + 1
Until $1 = 10
While 1 
   $msg = GUIGetMsg() 
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop 
Wend

If the loop is infinit it would be even better.

i realy dont know what to do at this rate.

Cheers.

Anti.

Link to comment
Share on other sites

Sorry for making such many questions but im learning programing and every 1 learns with errors xD.

heres the thing im making a GUI script and when i try to loop the script.

Heres my full script

#include <GUIConstants.au3> 
#NoTrayIcon 
GUICreate ("Testthing",450,280) 
$button1=GUICtrlCreateButton ("Start",1,68,445,30) 
GUICtrlSetTip ($button1,"Start","Start",0,1) 
$button3 = GUICtrlCreateButton ("Exit",400,20,40,40) 
GUICtrlSetTip ($button3,"Stop and Exit","Exit",0,1) 
GUICtrlCreateLabel ("To Pause the script Press Pause",10,1) 
GUICtrlCreateLabel ("To Exit Press Esc",10,15) 
GUICtrlCreateGroup ("Loot for",10,29,145,40) 
$time=GUICtrlCreateInput ("Time in Milliseconds",14,43,135,20) 
GUICtrlSetTip ($time,"Type in milliseconds how long you want to bot. To get the time 1sec= 1000 milliseconds 1000 1min= 60000 1 Hour= 3600000, 7200000= 2Hours and so on.","Time in Miliseconds",0,1) 
GUISetBkColor (0xEFFFFFF) 
$pic = GUICtrlCreatePic("",0,100,450,180) 
GUICtrlSetImage($pic, @ScriptDir & "\mainbg.jpg") 
GUISetState () 
Global $Paused 
Hotkeyset ("{Pause}","Pause") 
Hotkeyset ("{Esc}","Terminate") 
Func Pause () 
$Paused = NOT $Paused 
While $Paused 
Sleep (100) 
ToolTip ("Paused",0,0) 
WEnd 
ToolTip ("") 
EndFunc 
Func Terminate () 
Exit 0 
EndFunc 
While 1 
   $msg = GUIGetMsg() 
   Select 
       Case $msg = $GUI_EVENT_CLOSE 
           ExitLoop 
$i = 1
Do;This is the part that when i start the bot gives me an error saying "Case" statement with no matching "select" or "switch" statement. its like blocking the Select stame ment, i donno what to do.
Case $msg = $button1 
ToolTip ("Please go to Notepad Window to Begin") 
WinWaitActive ("NotePad","") 
ToolTip ("") 
Send ("f") 
Sleep (1000) 
Send ("f") 
Sleep (1000) 
   Case $msg = $button3 
   Exit 
  Case $msg = $time 
   WinWaitActive ("NotePad","") 
   Sleep (GUICtrlRead ($time)) 
   WinWaitClose ("NotePad","") 
   Run ("Notepad.exe") 
Sleep (2000) 
Send ("time has finished.",$lvl) 
Send ("{Enter}") 
Send ("ThankYou for using the script.") 
Send ("{Esc}") 
EndSelect 
WEnd 
$i = $i + 1
Until $1 = 10
While 1 
   $msg = GUIGetMsg() 
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop 
Wend

If the loop is infinit it would be even better.

i realy dont know what to do at this rate.

Cheers.

Anti.

I have no clue what you are trying to do, but use tidy and you will see your errors - in Scite hold down Ctrl and press T

Then fix your code and repost - and maybe put some spaces between your functions so that it is easier to read.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Well I can tell you one major mistake you made just by glancing over the code. You need all of your events to happen during your 'While 1' loop. If you want to get your program to work then take a minute and read the following a few times and make sure you understand what I am saying. If you get what I'm about to see you it will help you here and in future programs. AutoIt is NOT an object-oriented programming language. This means that when you run any AutoIt script, it will run line by line until it gets to the end of the last line, then it ends. Now there are things to can do to get around this such as adding delays to your program (Sleep()) but the most common way is using the 'While 1' loop. This gives you the ability to keep the program from ending until you want it to and you can have control over what happens when something is clicked. With that said here is (in my opinion) what the basic layout of an AutoIt script should be:

Create any variables that you will be using (if any).

Then create your window and all your buttons, etc. (GUI and controllers).

-Note: you should give all you controllers names. (EX: $button1 = GUICtrlCreateButton("My Button",25,100,40,40)

Now that you have everything set up you are ready to wait for the user to do something. Use a 'While 1' to keep your program open. Inside the loop user the GUIGetMsg() function with a case select. Now when the user pressed a

$button1 it will do whatever you want $button1 to do.

Finally, after the WEnd line add Functions that will be executed when $button1 is pressed.

Ok, so by now you're probably thinking I've said a bunch of junk, but how does this help YOU. Well here is an example of what I've just said.

#include <GuiConstants.au3>

#include <Array.au3>

;UI

Global $uiAll_Win = 0, $uiAll_Lost = 0, $uiAll_Un = 0, $uiAll_Total = 0

;Bot

Global $Paused, $Debug = "false", $xmax = 9, $ymax = 9, $minemax = 10

;HotKeys

HotKeySet("{PAUSE}", "TogglePause")

; GUI

GuiCreate("Auto Minesweeper GUI", 400, 500,0,0)

GuiSetIcon(@SystemDir & "\winmine.exe", 0)

; MENU

$FileMenu = GuiCtrlCreateMenu("File")

$ExitItem = GuiCtrlCreateMenuitem ("Exit",$filemenu)

; Buttons

$button1 = GUICtrlCreateButton("My Button 1",25,100,40,40)

$button2 = GUICtrlCreateButton("My Button 2",25,100,40,40)

$button3 = GUICtrlCreateButton("My Button 3",25,100,40,40)

; GUI MESSAGE LOOP

GuiSetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $exititem

ExitLoop

Case $msg = $button1

StartBot()

Case $msg = $button2

StopBot()

Case $msg = $button3

Something(0,"text")

EndSelect

WEnd

Function StartBot()

MouseClick("left",100,100)

If ... Then ...

EndFunc

Function StopBot()

If ... Then ...

EndFunc

Function Something($SomeVar,$SomeVar2)

If $SomeVar = 0 Then ...

if $SomeVar = "text" Then ...

EndFunc

Func TogglePause()

$Paused = NOT $Paused

While $Paused

sleep(100)

ToolTip('Script is "Paused"',0,0)

WEnd

ToolTip("")

WinActivate("Minesweeper")

FindPos()

EndFunc

Now don't try copying this code, pasting it into a blank script and running it because I doubt if it will really work. (Well I guess you can if you really feel like it. Couldn't hurt.) This is some chopped up code of a program that I made but if gives you a template.

#include

Dim

Hotkey (run a function when a key on the keyboard is pressed)

GUI

Controllers

While 1

-Select case

--controller is clicked

---what do what when controller is clicked (which function to run)

-end case

wend

functions (ran when controller is clicked or when a hotkey is pressed)

Well, I hope this helped you out. Once again I recommend you read this over at least 2 or 3 times and make sure you understand the general layout (don't worry, you don't have to understand every single line, guess understand the idea and why the idea works). I also recommend coping all of this and saving it in a text file on your computer so you can refer back to it in the future. Hope this helps you out!

~Bryan AKA Flint Brenick~

Edited by FlintBrenick
Link to comment
Share on other sites

AutoIt is NOT an object-oriented programming language. This means that when you run any AutoIt script, it will run line by line until it gets to the end of the last line, then it ends.

~Bryan AKA Flint Brenick~

With everything that was written - this is the only thing that sticks out and should be corrected. Though AutoIt is not an object-oriented programming language - it does not differ from one the way the code is ran - one line at a time. This is how most code will run and you can skip code by using conditions and function calls. If I am wrong I am sure I will hear it, but object-oriented programming languages goal is to stick all variables and functions dealing with a certain object. Lets say a car is the object and the car can have variables like wheel types and paint color. And a function of the car might be installing tiers or the engine. You can see how this code can be used for 100's of cars - not just one.

Hope it helps.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

no gabb... just cleaned it up for you...

nice effort

#include <GUIConstants.au3>
#NoTrayIcon

Global $Paused, $lvl

HotKeySet("{Pause}", "Pause")
HotKeySet("{Esc}", "Terminate")

GUICreate("Testthing", 450, 280)
$button1 = GUICtrlCreateButton("Start", 1, 68, 445, 30)
GUICtrlSetTip($button1, "Start", "Start", 0, 1)
$button3 = GUICtrlCreateButton("Exit", 400, 20, 40, 40)
GUICtrlSetTip($button3, "Stop and Exit", "Exit", 0, 1)
GUICtrlCreateLabel("To Pause the script Press Pause", 10, 1)
GUICtrlCreateLabel("To Exit Press Esc", 10, 15)
GUICtrlCreateGroup("Loot for", 10, 29, 145, 40)
$time = GUICtrlCreateInput("Time in Milliseconds", 14, 43, 135, 20)
GUICtrlSetTip($time, "Type in milliseconds how long you want to bot. To get the time 1sec= 1000 milliseconds 1000 1min= 60000 1 Hour= 3600000, 7200000= 2Hours and so on.", "Time in Miliseconds", 0, 1)
GUISetBkColor(0xEFFFFFF)
$pic = GUICtrlCreatePic("", 0, 100, 450, 180)
GUICtrlSetImage($pic, @ScriptDir & "\mainbg.jpg")
GUISetState()


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button1
            ToolTip("Please go to Notepad Window to Begin")
            WinWaitActive("NotePad", "")
            ToolTip("")
            Send("f")
            Sleep(1000)
            Send("f")
            Sleep(1000)
        Case $msg = $button3
            Exit
        Case $msg = $time
            WinWaitActive("NotePad", "")
            Sleep(GUICtrlRead($time))
            WinWaitClose("NotePad", "")
            Run("Notepad.exe")
            Sleep(2000)
            Send("time has finished.", $lvl)
            Send("{Enter}")
            Send("ThankYou for using the script.")
            Send("{Esc}")
    EndSelect
WEnd


Func Pause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip("Paused", 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>Pause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

With everything that was written - this is the only thing that sticks out and should be corrected. Though AutoIt is not an object-oriented programming language - it does not differ from one the way the code is ran - one line at a time. This is how most code will run and you can skip code by using conditions and function calls. If I am wrong I am sure I will hear it, but object-oriented programming languages goal is to stick all variables and functions dealing with a certain object. Lets say a car is the object and the car can have variables like wheel types and paint color. And a function of the car might be installing tiers or the engine. You can see how this code can be used for 100's of cars - not just one.

Hope it helps.

My main point was that they really need to set up their script with something like 'While 1' and having all the events take place within the 'While 1' which will allow the to control what takes place in the script. Anyway between what I said and what you said hopefully any newbs reading this thread will atleast get the idea.

~Flint~

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...