Jump to content

Looping Not Working


Recommended Posts

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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