Jump to content

help on loop


 Share

Recommended Posts

@second

Global $Paused
#include <GUIConstants.au3>
Opt("trayiconhide", 1)
HotKeySet("{F1}", "bot")
HotKeySet("{ESC}", "Terminate")
HotKeySet("{F2}", "standby")
$GUI = GUICreate("Bot trial", 190, 230, -1, -1)
$Label_1 = GUICtrlCreateLabel("Type colour code:", 10, 10, 130, 15)
$Input_1 = GUICtrlCreateInput("11437410", 10, 30, 100, 20)
$start = GUICtrlCreateButton("start bot", 10, 61, 90, 30)
$stop = GUICtrlCreateButton("stop bot", 100, 61, 90, 30)
$Credits = GUICtrlCreateLabel("Credits:" & @CRLF & "Second", 130, 2)
$Label_2 = GUICtrlCreateLabel("Shade variaty", 10, 95, 170, 30)
$Input_2 = GUICtrlCreateInput("", 10, 110, 100, 23)
GUISetState(@SW_SHOW)
$nMsg = GUIGetMsg()
$colour = GUICtrlRead($Input_1)
$shade = GUICtrlRead($Input_2)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit 0 Or Call("Terminate")
        Case $nMsg = $start
            Call("bot")
        Case $nMsg = $stop
            Call("standby")
    EndSelect
WEnd

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

Func standby()
    While 2
        Sleep(1000)
    WEnd
EndFunc   ;==>standby



Func bot()
    While 1

        $k = MouseGetPos()
        $pos = PixelSearch($k[0] - 250, $k[1] - 250, $k[0] + 250, $k[1] + 350, $colour, $shade)
        If Not @error Then
            MouseMove($pos[0], $pos[1])
            MouseClick("left")
            Sleep(100)
            MouseMove(303, 409)
            Sleep(6000)
        Else
            MsgBox(64, "error", "failed to find the provided pixel retry in 1 sec", 1)
            Sleep(1000)
        EndIf
    WEnd
EndFunc   ;==>bot

Cheers, FireFox.

Link to comment
Share on other sites

bump! i need to end a loop in func by pressing gui button-$stop, any ideas?

You can

Use a hotkey

OR

Check for the button press with another $msg = GuiGetMsg() section in your loop

OR

use OnEvent mode to get out of it by pressing a button.

The function must not be called by an event.

The event called by the button can set a global variable which is tested in the loop in the function. You could have something like

If $endlopp then return.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

@Second

Maybe...

#include <GUIConstants.au3>

#NoTrayIcon
global $endloop=1

HotKeySet("{F1}", "bot")
HotKeySet("{ESC}", "_Terminate")
HotKeySet("{F2}", "_standby")

$GUI = GUICreate("Rs bot", 190, 230, -1, -1)
$Label_1 = GUICtrlCreateLabel("Type colour code:",10, 10, 130, 15)
$Input_1 = GUICtrlCreateInput("11437410", 10, 30, 100, 20)
$start = GUICtrlCreateButton("start bot", 10, 61, 90, 30)
$stop = GUICtrlCreateButton("stop bot", 100, 61, 90, 30)
$Credits = GUICtrlCreateLabel("Credits:" & @CRLF & "Seltas", 130, 2)
$Label_2 = GUICtrlCreateLabel("Shade variaty", 10, 95, 170, 30)
$Input_2 = GUICtrlCreateInput("", 10, 110, 100, 23)
$coins = GUICtrlCreateCheckbox("Pickup coins?",10, 150)

$nMsg = GUIGetMsg()
$colour=GUICtrlRead($Input_1)
$shade=GUICtrlRead($Input_2)
GUISetState(@SW_SHOW)
while 1
Select
Case $nMsg = $GUI_EVENT_CLOSE
Exit
case $nMsg=$start
bot()
case $nMsg = $stop
send("{F2}")
endselect
wend

Func _Terminate()
    Exit
EndFunc   ;==>_Terminate, exits scirpt

Func _standby()
    Global $endloop = 0
EndFunc   ;==>_standby ends the bot() func


Func bot();=====the main bot script
  Global $endloop=1
  While 1
$nmsg = GuiGetMsg()
Select
Case $nmsg = $stop
Global $endloop=0
ExitLoop
EndSelect    
    If $endloop=0 then exitloop
          $k = MouseGetPos()
          $pos = PixelSearch($k[0] - 250, $k[1] - 250, $k[0] + 250, $k[1] + 250, $colour, $shade)
          If Not @error Then
            MouseMove($pos[0], $pos[1])
            MouseClick("left")
            Sleep(100)
            MouseMove(303, 409)
            Sleep(6000)
          Else
            MsgBox(64, "error", "failed to find "&$colour&", retry in 1 sec", 1)
            Sleep(1000)
          endif
  wend
        endfunc

Cheers, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Im almost done with this example bot i want to post but can't find a way to get GUI to work in funcs' loop, tried looping func in select case but failed...

Any suggestions?

edit: sorry, I wasn't aware of that

Second

Edited by second
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...