Jump to content
Sign in to follow this  
truther242

Checking for a condition throughout the script

Recommended Posts

truther242

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

Share this post


Link to post
Share on other sites
Melba23

truther242,

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

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
truther242

truther242,

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

M23

works amazingly thanks :D

Share this post


Link to post
Share on other sites
truther242

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

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
truther242

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

Share this post


Link to post
Share on other sites
kylomas

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

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  

×