Sign in to follow this  
Followers 0
Bruntale

Looping Not Working

4 posts in this topic

I read all the forums I could and I came down to it, the While 1 and WEnd are the ones I need.

BUT when I use them, it makes my script not work.

While 1
   if checkrequest() Then
    sleep(1020000)
   Else
    sleep(120000)
    endif
   WEnd

That is my code. If I do not include the "While 1" and the "WEnd" it only works once, go figure. But when I include them it works but it works to the point that when it looks to see if the value for "checkrequest()" is true or not, it bypasses it and just keeps running the "checkrequest()" function, not moving on to other functions.

As in, if "checkrequest()" returns True it starts another function. If it is False, I want it to wait 2 minutes and run "checkrequest()" again. With that being said, I need it to run "checkrequest()" every 15-20 minutes, but its not allowing the "checkrequest()" to do its process. It just keeps running it.

Any help?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

if you post your full code i could help you much more, but it looks like your code is checking for true or false, and sleeping. nothing else

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

i would do something like this:

While 1
   checkrequest()
   if $result = True Then
    sleep(1020000)
   Else
    sleep(120000)
    endif
   WEnd

Func checkrequest()
$result = False
...
some code
...

If $var = Success Then $result = True
EndFunc

the last line needs to be coded however you can.

Edited by Kidney

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The easiest way to get this to work is by calling (whatever) functions inside your loop. If you want to exit the loop use ExitLoop. If you want to run a test function repeatedly at given intervals you could also use AdLibRegister. The code below is just an illustration which you should run in SciTE editor (using the hotkey F5). You should try to follow the logic of the code and read the comments. Hopefully it will give you an idea how to proceed with your script.

While 1
    If checkrequest() Then ; Run Function - checkrequest
        ConsoleWrite("Return Value True" & @LF) ; Run Function - ConsoleWrite
        Sleep(1000) ; Run Function - Sleep
    Else
        ConsoleWrite("Return Value False" & @LF) ; Run Function - ConsoleWrite
        Sleep(2000) ; Run Function - Sleep
        ContinueLoop ; Skip the next part of the loop and repeat from the start.
    EndIf
    ; Moving on to another function
    MsgBox(0, "", "5 Second Sleep") ; Run Function - MsgBox
    Sleep(5000) ; Run Function - Sleep
WEnd

Func checkrequest()
    Local $bRet = False
    If Random(0,1,1) Then $bRet = True
    Return $bRet
EndFunc
Edited by czardas

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  
Followers 0