Jump to content

Checking for a condition throughout the script


Recommended Posts

So let's say that I have a script that writes words in notepad. It’s all working great until notepad suddenly decides to crash. How do I make sure that the program constantly checks “has notepad crashed?” while still running the main code?

So for example

$test = winactive(“notepad.exe”)
If $test = 0 then ;notepad crashed

How would I keep this running WHILE my code writes in notepad? If I were just to write

While 1
$test = winactive(“notepad.exe”)
If $test = 0 then ;notepad crashed

Well the code would be stuck here and the rest of the code would not be executed.

What I want to do is constantly check if notepad has crashed if it has stop whatever the main code is doing an relaunch notepad

Hope you understand :D

Link to comment
Share on other sites

  • Moderators

truther242,

Use an Adlib function to check at regular intervals - your main script is only momentarily interrupted each time. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

truther242,

Use an Adlib function to check at regular intervals - your main script is only momentarily interrupted each time. :)

M23

Until I tested it a few times it worked amazingly :> Anyways my problem is that after the adlib has been executed and relaunched notepad.exe the adlib function that runs throughout the program stops. How do I keep the function running after fixing the first crash?

I tried this but it does not seem to make the adlib function check every 250 ms again :<

AdlibRegister("Order",250)
Func order()
$test = WinActive("Notepad")
If $test = 0 then relauncnotepad()
endfunc
relauncnotepad()
AdlibRegister("Order",250)
Etc..
endfunc
Edited by truther242
Link to comment
Share on other sites

truther242,

The adlib will not stop till you unregister it. Your problem lies elsewhere. Are you sure that this test is true when you expect it to be?

If $test = 0 then relauncnotepad()

Also, how is notepad stopping?

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

this is the code

AdlibRegister("Order",250)
$Time = _Timer_Init()
main()

func main()
while 1
WinActivate("ChillControl V.exe")
MouseClick("left",438,423,2)
sleep(2000)
MouseClick("left",426,357,2)
sleep(2000)
MouseClick("left",442,580,2)

sleep(2000)

if $RunTime > 0.1 Then
WinActivate("ChillControl V.exe")
Send("!+{F4}")
$QTS = 1
EndIf

WEnd

EndFunc

func Order()
$Spot = WinActive("ChillControl V.exe")
$RunTime = _Timer_Diff($Time)
$RunTime = $RunTime / 1000
$RunTime = $RunTime / 60
ToolTip("RUNTIME " & $RunTime, 0 , 0)
if $Spot= 0 AND $QTS = 1 Then reset()

EndFunc
func reset()
Run("C:Program Files (x86)Antec CCChillControl V.exe")
sleep(2000)
$QTS = 0
$Time = _Timer_Init()
main()

EndFunc

for some reason the adlib function stops running after first reset

Edited by truther242
Link to comment
Share on other sites

truther242,

Tooltip may be blocking. Send your calc back to the main loop with a variable and issue the tooltip there.

kylomas

edit: I also would not call another func from the adlib. Send a true/false variable back to the mainloop and call from there.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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...