Sign in to follow this  
Followers 0
iRAWRRichard

Running a function while performing a check at the same time

12 posts in this topic

How do I write a script in which it'll detect whether the client has exited? If the client has exited, I want it to exit the loop of the current function it's performing and perform another function to get the client reopened.

Share this post


Link to post
Share on other sites



Please see function AdlibRegister. This lets you register a function that is called every x milliseconds. In this function you can check the status of the client and do whatever you want. When you end the function the script keeps on processing where it left.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Is there a thank button somewhere? :] Thanks!

Share this post


Link to post
Share on other sites

Just saying thank you is enough :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Since the AdlibRegister function checks back every few intervals, is there an optimal time I should put for it? I don't want to put something so low that would cause CPU stress, unless this doesn't stress the CPU that much anyways.

Share this post


Link to post
Share on other sites

It depends on your application. What happens if the client exits? How fast have you to detect this change?

But I think to set a value of 250 or 500 (means 4 or 2 checks per second) will be fine.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Alright thank you! Also thanks for the quick replies. I honestly wasn't expecting an answer until tomorrow.

Edited by iRAWRRichard

Share this post


Link to post
Share on other sites

iRAWRRichard,

You will probably find that for water (and for me) it is already tomorrow! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

The check works when the function is somewhere close to the beginning. However as the function gets closer to the middle, the check stops working :/

Share this post


Link to post
Share on other sites

iRAWRRichard,

It is obvious that the error is on Line 23487 - you have spurgled the exobrox at that point. ;)

.....

Seriously, how are we supposed to help you with so few clues? Please post the code you have - but please use Code tags. Put [autoit] before and [/autoit] after your posted code. :D

Once we see what is going on we can offfer more sensible advice. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Ahh sorry haha. Well here's my full script :]

HotKeySet("{F1}", "Start")
HotKeySet("{F2}", "Stop")
Opt("MouseCoordMode", 2)
Opt("PixelCoordMode", 2)
AdlibRegister("CheckClient", 5000)
$RUNCOUNTER = 0
$TIMEOUT = 165000
$TIMEEXIT = 150000
Const $ID = ""
Const $PASSWORD = ""
Const $CHANNEL = 6 ; will change into array
Const $CHARACTER = 2 ; will change into array
While 1
DisplayToolTip(0)
WinWaitActive("Client", "")
WEnd
Func CheckClient()
If Not ProcessExists("Client.exe") Then
  StartClient()
  Login()
  Start()
EndIf
EndFunc
Func StartClient()
ShellExecute("C:Client.exe")
EndFunc
Func Login()
Do
  PixelSearch(482, 414, 482, 414, 0xFFFFFF, 1)
Until Not @error
WinSetOnTop("Client", "", 1)
WinActivate("Client")
MouseClick("left", 400, 300)
Do
  PixelSearch(61, 94, 61, 94, 0xDDEE88, 1)
Until Not @error
MouseClick("left", 398, 291, 2)
ControlSend("Client", "", "", $ID)
ControlSend("Client", "", "", "{TAB}")
ControlSend("Client", "", "", $PASSWORD)
ControlSend("Client", "", "", "{ENTER}")
Do
  PixelSearch(135, 57, 135, 57, 0xFFCC00, 1)
Until Not @error
MouseClick("left", 162, 59)
Do
  PixelSearch(251, 249, 251, 249, 0xFFDD00, 1)
Until Not @error
MouseClick("left", 260, 327, 2)
Do
  PixelSearch(117, 153, 117, 153, 0xFF7700, 1)
Until Not @error
ControlSend("Client", "", "", "{ENTER}")
Do
  PixelSearch(371, 245, 371, 245, 0xFFBB00, 1)
Until Not @error
ControlSend("Client", "", "", "{ENTER}")
EndFunc
Func Start()
WinActivate("Client")
WinSetOnTop("Client", "", 1)
WinMove("Client", "", 0, 0)
Do
  PixelSearch(482, 414, 482, 414, 0xCCEEEE, 2)
Until Not @error
MouseClick("left", 564, 555)
Do
  PixelSearch(431, 353, 431, 353, 0xFF0000, 2)
Until Not @error
ControlSend("Client", "", "", "{DOWN}")
ControlSend("Client", "", "", "{ENTER}")
Do
  PixelSearch(431, 392, 431, 392, 0xFF0000, 2)
Until Not @error
ControlSend("Client", "", "", "{ENTER}")
Call("StageOne")
EndFunc
Func StageOne()
WinActivate("Client")
$RUNCOUNTER = $RUNCOUNTER + 1
Do
  PixelSearch(445, 237, 445, 237, 0xDDDDDD, 1)
Until Not @error
DisplayToolTip(1)
$TIMER = TimerInit()
Send("{RIGHT down}")
Sleep(700)
Send("{RIGHT up}")
While TimerDiff($TIMER) <= $TIMEOUT
  Do
   Do
    PixelSearch(660, 450, 885, 546, 0x309C29, 20)
   Until Not @error
   Send("{S down}")
   PixelSearch(660, 450, 885, 546, 0x309C29, 20)
  Until @error
  Send("{S up}")
WEnd
Call("StageTwo")
EndFunc
Func StageTwo()
Do
  PixelSearch(444, 238, 444, 238, 0xDDDDDD, 1)
Until Not @error
DisplayToolTip(2)
$TIMER = TimerInit()
Send("{RIGHT down}")
Sleep(700)
Send("{RIGHT up}")
While TimerDiff($TIMER) <= $TIMEOUT
  Do
   Do
    PixelSearch(660, 450, 885, 546, 0xCC0000, 10)
   Until Not @error
   Send("{S down}")
   PixelSearch(660, 450, 885, 546, 0xCC0000, 10)
  Until @error
  Send("{S up}")
WEnd
Do
  PixelSearch(386, 275, 286, 275, 0xFFEEEE, 1)
Until Not @error
Call("StageThree")
EndFunc
Func StageThree()
Do
  PixelSearch(445, 236, 445, 236, 0xDDDDDD, 1)
Until Not @error
DisplayToolTip(3)
$TIMER = TimerInit()
Send("{RIGHT down}")
Sleep(700)
Send("{RIGHT up}")
While TimerDiff($TIMER) <= $TIMEEXIT
  Do
   Do
    PixelSearch(660, 450, 885, 546, 0x557799, 10)
   Until Not @error
   Send("{S down}")
   PixelSearch(660, 450, 885, 546, 0x557799, 10)
  Until @error
  Send("{S up}")
WEnd
MouseClick("left", 190, 214)
Do
  PixelSearch(431, 393, 431, 393, 0xFF0000, 2)
Until Not @error
ControlSend("Client", "", "", "{ENTER}")
Call("Start")
EndFunc
Func DisplayToolTip($STAGE)
ToolTip("Number of runs: " & $RUNCOUNTER & @CRLF & "Stage: " & $STAGE & @CRLF & "Press F1 to start" & @CRLF & "Press F2 to quit", @DesktopWidth, 0, "Bot", 0, 4)
EndFunc
Func Stop()
WinSetOnTop("Client", "", 0)
Exit
EndFunc

I just ran another test just now and the check ran fine, however around an hour ago the check didn't work. Just take a look at it and tell me what could be wrong. Also I realize my script is poorly coded, any tips on improving it? :]

Edited by iRAWRRichard

Share this post


Link to post
Share on other sites

iRAWRRichard,

Subway PQ Bot

<Sigh>

Unfortunately you appear not to have read the Forum Rules. Please read them now and then you will understand why you will get no more help and this thread will shortly be locked. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0