Jump to content
Sign in to follow this  
sandin

adlib func just stops working, why?

Recommended Posts

sandin

Here's the script:

#include <GuiConstants.au3>
#Include <Constants.au3>
#include <Process.au3>
#include <INet.au3>
#include <misc.au3>

hotkeyset("{NUMPAD0}", "STOPP")
hotkeyset("{NUMPAD1}", "func4")
hotkeyset("{NUMPAD2}", "end")

Global $ggg
Global $starttime1
Global $starttime2
Global $starttime3
Global $starttime4
Global $aaa
Global $bbb
Global $ccc
Global $mmm
Global $nnn
Global $ooo
$time = 5000;5 sec
$starttime4=TimerInit()
$time2 = 120000;2 min

AdlibEnable("myadlib", 10)

func myadlib ()
    if $aaa=1 Then
        if TimerDiff($starttime1)>$time Then
            call ("func1")
        EndIf
    EndIf
    if $bbb=1 Then
        if TimerDiff($starttime2)>$time Then
            call ("func2")
        EndIf
    EndIf
    if $ccc=1 Then
        if TimerDiff($starttime3)>$time Then
            call ("func3")
        EndIf
    EndIf
    If TimerDiff($starttime4)>$time2 Then
        msgbox(262144, "time ended", "time ended, script will close now.")
        call ("end")
    EndIf
EndFunc

Func STOPP ()
    $ggg += 1
    TrayTip("notice", "you have called stop " & $ggg & " times.", 10)
    $aaa = 0
    $bbb = 0
    $ccc = 0
While 1
Sleep(10)
Wend
EndFunc

func end ()
    Exit
EndFunc

func again ()
;nothing
EndFunc

func func1 ()
    $mmm += 1
    sleep (1000)
    TrayTip('notice', 'You have called func1 ' & $mmm & ' times.', 10)
    $starttime1=TimerInit()
EndFunc

func func2 ()
    $nnn += 1
    sleep (1000)
    TrayTip('notice', 'You have called func2 ' & $nnn & ' times.', 10)
    $starttime2=TimerInit()
EndFunc

func func3 ()
    $ooo += 1
    sleep (1000)
    TrayTip('notice', 'You have called func3 ' & $ooo & ' times.', 10)
    $starttime3=TimerInit()
EndFunc

Func func4 ()
    call ("func1")
    $aaa = 1
    call ("func2")
    $bbb = 1
    call ("func3")
    $ccc = 1
        $xkoordinata = 0
        $ykoordinata = 0
        $speed2 = 10
        while 1
            call ("again")
            MouseDown( "Right")
                        MouseMove(337, 299 , $speed2)
            MouseDown( "Right")
                        MouseMove( 287 , 246 , $speed2)
            MouseDown( "Right")
                        MouseMove( 432 , 246 , $speed2)
            MouseDown( "Right")
                        MouseMove( 402 , 171 , $speed2)
            MouseDown( "Right")
                        MouseMove( 467, 191, $speed2)
            MouseDown( "Right")
                        MouseMove( 517 , 253 , $speed2)
            MouseDown( "Right")
                        MouseMove( 447 ,301, $speed2)
            MouseDown( "Right")
                        MouseMove( 397 ,311, $speed2)
            MouseUp("Right")
        WEnd
EndFunc
    
while 1
    sleep (10)
WEnd

and the problem is following: If I hold down NumPad0 till it counts more than 100 times, then run the func with NumPad1, let it do 1 circle, and then hit NumPad0 to stop it, after running func4 with NumPad1 adlib won't work anymore. Why's that???

Share this post


Link to post
Share on other sites
martin

Here's the script:

#include <GuiConstants.au3>
#Include <Constants.au3>
#include <Process.au3>
#include <INet.au3>
#include <misc.au3>

hotkeyset("{NUMPAD0}", "STOPP")
hotkeyset("{NUMPAD1}", "func4")
hotkeyset("{NUMPAD2}", "end")

Global $ggg
Global $starttime1
Global $starttime2
Global $starttime3
Global $starttime4
Global $aaa
Global $bbb
Global $ccc
Global $mmm
Global $nnn
Global $ooo
$time = 5000;5 sec
$starttime4=TimerInit()
$time2 = 120000;2 min

AdlibEnable("myadlib", 10)

func myadlib ()
    if $aaa=1 Then
        if TimerDiff($starttime1)>$time Then
            call ("func1")
        EndIf
    EndIf
    if $bbb=1 Then
        if TimerDiff($starttime2)>$time Then
            call ("func2")
        EndIf
    EndIf
    if $ccc=1 Then
        if TimerDiff($starttime3)>$time Then
            call ("func3")
        EndIf
    EndIf
    If TimerDiff($starttime4)>$time2 Then
        msgbox(262144, "time ended", "time ended, script will close now.")
        call ("end")
    EndIf
EndFunc

Func STOPP ()
    $ggg += 1
    TrayTip("notice", "you have called stop " & $ggg & " times.", 10)
    $aaa = 0
    $bbb = 0
    $ccc = 0
While 1
Sleep(10)
Wend
EndFunc

func end ()
    Exit
EndFunc

func again ()
;nothing
EndFunc

func func1 ()
    $mmm += 1
    sleep (1000)
    TrayTip('notice', 'You have called func1 ' & $mmm & ' times.', 10)
    $starttime1=TimerInit()
EndFunc

func func2 ()
    $nnn += 1
    sleep (1000)
    TrayTip('notice', 'You have called func2 ' & $nnn & ' times.', 10)
    $starttime2=TimerInit()
EndFunc

func func3 ()
    $ooo += 1
    sleep (1000)
    TrayTip('notice', 'You have called func3 ' & $ooo & ' times.', 10)
    $starttime3=TimerInit()
EndFunc

Func func4 ()
    call ("func1")
    $aaa = 1
    call ("func2")
    $bbb = 1
    call ("func3")
    $ccc = 1
        $xkoordinata = 0
        $ykoordinata = 0
        $speed2 = 10
        while 1
            call ("again")
            MouseDown( "Right")
                        MouseMove(337, 299 , $speed2)
            MouseDown( "Right")
                        MouseMove( 287 , 246 , $speed2)
            MouseDown( "Right")
                        MouseMove( 432 , 246 , $speed2)
            MouseDown( "Right")
                        MouseMove( 402 , 171 , $speed2)
            MouseDown( "Right")
                        MouseMove( 467, 191, $speed2)
            MouseDown( "Right")
                        MouseMove( 517 , 253 , $speed2)
            MouseDown( "Right")
                        MouseMove( 447 ,301, $speed2)
            MouseDown( "Right")
                        MouseMove( 397 ,311, $speed2)
            MouseUp("Right")
        WEnd
EndFunc
    
while 1
    sleep (10)
WEnd

and the problem is following: If I hold down NumPad0 till it counts more than 100 times, then run the func with NumPad1, let it do 1 circle, and then hit NumPad0 to stop it, after running func4 with NumPad1 adlib won't work anymore. Why's that???

Don't know.

Put $aaa = 0 at the start of func1, $bbb = 0 at the start of func 2, $ccc = 0 at the start of fun3 so that myadlib doesn't call them while they are still executing.


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.

Share this post


Link to post
Share on other sites
sandin
sylvanie

hello,

you have too much infinte recursive while, and I noticed that it can make some trouble shoot with adlibenable

the first while 1 give us the time to press 0 1 2, ok

when you press 0 1 0 1 then you are calling 4 functions without terminating ones :

0:

while 1

sleep    - > 1 :  
                        while 1
                        ...        -> 0 :
                       wend               while 1    etc ...
wend

so, a simple way to notice func4 that it has to terminate the while loop is to use a global, which is updated by the stop function :

#include <GuiConstants.au3>
#Include <Constants.au3>
#include <Process.au3>
#include <INet.au3>
#include <misc.au3>

hotkeyset("{NUMPAD0}", "STOPP")
hotkeyset("{NUMPAD1}", "func4")
hotkeyset("{NUMPAD2}", "end")

Global $ggg
Global $starttime1
Global $starttime2
Global $starttime3
Global $starttime4
Global $aaa
Global $bbb
Global $ccc
Global $mmm
Global $nnn
Global $ooo
Global $func4_is_running=0; global to notice func4 if it has to continue the loop or not

$time = 5000;5 sec
$starttime4=TimerInit()
$time2 = 120000;2 min

AdlibEnable("myadlib", 10)

func myadlib ()
    if $aaa=1 Then
        if TimerDiff($starttime1)>$time Then
            call ("func1")
        EndIf
    EndIf
    if $bbb=1 Then
        if TimerDiff($starttime2)>$time Then
            call ("func2")
        EndIf
    EndIf
    if $ccc=1 Then
        if TimerDiff($starttime3)>$time Then
            call ("func3")
        EndIf
    EndIf
    If TimerDiff($starttime4)>$time2 Then
        msgbox(262144, "time ended", "time ended, script will close now.")
        call ("end")
    EndIf
EndFunc

Func STOPP ()
    $ggg += 1
    TrayTip("notice", "you have called stop " & $ggg & " times.", 10)
    $aaa = 0
    $bbb = 0
    $ccc = 0
    $func4_is_running=0; will notice func4 that it must terminate the current loop and exit
EndFunc

func end ()
    Exit
EndFunc

func again ()
;nothing
EndFunc

func func1 ()
    $mmm += 1
    sleep (1000)
    TrayTip('notice', 'You have called func1 ' & $mmm & ' times.', 10)
    $starttime1=TimerInit()
EndFunc

func func2 ()
    $nnn += 1
    sleep (1000)
    TrayTip('notice', 'You have called func2 ' & $nnn & ' times.', 10)
    $starttime2=TimerInit()
EndFunc

func func3 ()
    $ooo += 1
    sleep (1000)
    TrayTip('notice', 'You have called func3 ' & $ooo & ' times.', 10)
    $starttime3=TimerInit()
EndFunc

Func func4 ()
    $func4_is_running=1
    $break_while=1
    call ("func1")
    $aaa = 1
    call ("func2")
    $bbb = 1
    call ("func3")
    $ccc = 1
        $xkoordinata = 0
        $ykoordinata = 0
        $speed2 = 10
        while $func4_is_running=1
            call ("again")
            MouseDown( "Right")
                        MouseMove(337, 299 , $speed2);you can test $func4_is_running before each action if you want to interrupt the loop before ending the current step 
            MouseDown( "Right")
                        MouseMove( 287 , 246 , $speed2)
            MouseDown( "Right")
                        MouseMove( 432 , 246 , $speed2)
            MouseDown( "Right")
                        MouseMove( 402 , 171 , $speed2)
            MouseDown( "Right")
                        MouseMove( 467, 191, $speed2)
            MouseDown( "Right")
                        MouseMove( 517 , 253 , $speed2)
            MouseDown( "Right")
                        MouseMove( 447 ,301, $speed2)
            MouseDown( "Right")
                        MouseMove( 397 ,311, $speed2)
            MouseUp("Right")
        WEnd
EndFunc
    
while 1
    sleep (10)
WEnd
Edited by sylvanie

Share this post


Link to post
Share on other sites
sandin
SmOke_N

Is this remotely similar to anything you are attempting (Just remembered it... it's been a while and I've slept once or twice since then :) )

http://www.autoitscript.com/forum/index.ph...st&p=270164


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
sandin
sylvanie

verify the value of $func4_is_running before each Mousedown

while $func4_is_running=1
            call ("again")
            if $func4_is_running=0 then exitloop
            MouseDown( "Right")
                        MouseMove(337, 299 , $speed2);you can test $func4_is_running before each action if you want to interrupt the loop before ending the current step 
            
           if $func4_is_running=0 then exitloop
           MouseDown( "Right")
                        MouseMove( 287 , 246 , $speed2)

            if $func4_is_running=0 then exitloop
            MouseDown( "Right")
                        MouseMove( 432 , 246 , $speed2)
           if $func4_is_running=0 then exitloop
            MouseDown( "Right")
                        MouseMove( 402 , 171 , $speed2)
            ....
WEnd

Share this post


Link to post
Share on other sites
sandin
sylvanie

It s just a personnal observation.

I have this problem with some scripts which include several infinite loop, or action which take 100% cpu.

Now I don't know realy why this problem exists.


Share this post


Link to post
Share on other sites
sandin
therks

Beats me. That's just not what Call() is for. Call is for calling functions with variable strings. If you want to call the function "MyFunc" use MyFunc().

Func MyFunc()
  MsgBox(0, 'MyFunc', 'Don''t use Call() for me.')
EndFunc

MyFunc()

Share this post


Link to post
Share on other sites
SmOke_N

so, if I remove Call("again") func (which has nothing inside of it), I won't get recursion error after while $func4_is_running=1 makes ~383 loops?

You'll still get the recursion error. Try placing a Return statement at the bottom of each function where the function would normally return and you'll not have to concern yourself with recursion (unless you keep calling the function from within itself).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×