Jump to content
Sign in to follow this  
MadaraUchiha

Looping Strange Behaviour

Recommended Posts

MadaraUchiha

Yo,

I am currently on my mobile phone so I can't post my code...

But basiclly I have a logic error in my loop.

I have a Do Until Loop, which I start with a button click. Once started, it download every 3 seconds a string from my server and compare it with another variable. The string on the server is not available all the time, so I made an If statement in my loop. If not returns '' (nothing) then compare, else, if it is nothing, wait 5 seconds, then start again with the loop.

If the string is available everything works fine. If not it goes into the else statement, tells me string not available, waits 5 seconds, and now, I stuck. I want to start the loop again. I tried ContinueLoop, but then it repeats normally but even if I change the string on my server it downloads it and tells me its nothing, even if it is not!?

So fact is, after not finding string the first time, it loops again and again, and even if the string will change on server, it still tells me: String is nothing, instead of jumping into the compare step.

Any help?

How would I structure a good loop in case of failure and repeat it from beginning?


Share this post


Link to post
Share on other sites
michaelslamet

Hi,

Something like this?

$hGUI = GuiCreate("My GUI", 200, 200)
$hButtonCompare = GUICtrlCreateButton("Compare", 100, 100, 50)
GUISetState(@SW_SHOW, $hGUI)

Do
    $aMsg = GUIGetMsg()
    Select
        case $aMsg = $hButtonCompare
            Do
                If DownloadStringFromServer() <> "" Then
                    ConsoleWrite("String is availble" & @CRLF)
                    Sleep(3000)
                Else
                    ConsoleWrite("String not available!" & @CRLF)
                    Sleep(5000)
                EndIf
            Until False
    EndSelect
Until False

Func DownloadStringFromServer()
    Local $a = Random(1,10,1)
    If Mod($a, 2) = 0 Then
        Return ""
    Else
        Return "String"
    EndIf
EndFunc
  • Like 1

Share this post


Link to post
Share on other sites
Jfish

Have you considered using the AdlibRegister function instead of a loop?

Remarks

Every 250 ms (or time ms) the specified "function" is called--typically to check for unforeseen errors. For example, you could use adlib in a script which causes an error window to pop up unpredictably.
The adlib function should be kept simple as it is executed often and during this time the main script is paused. Also, the time parameter should be used carefully to avoid CPU load.

Several Adlib functions can be registered. Re-registering an already existing Adlib function will update it with a new time.

 


Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
MadaraUchiha

Thanks to both of you.

JFish, can u give me an example? Adlibregister, how to use it instead of a loop?


Share this post


Link to post
Share on other sites
MadaraUchiha

 

Hi,

Something like this?

$hGUI = GuiCreate("My GUI", 200, 200)
$hButtonCompare = GUICtrlCreateButton("Compare", 100, 100, 50)
GUISetState(@SW_SHOW, $hGUI)

Do
    $aMsg = GUIGetMsg()
    Select
        case $aMsg = $hButtonCompare
            Do
                If DownloadStringFromServer() <> "" Then
                    ConsoleWrite("String is availble" & @CRLF)
                    Sleep(3000)
                Else
                    ConsoleWrite("String not available!" & @CRLF)
                    Sleep(5000)
                EndIf
            Until False
    EndSelect
Until False

Func DownloadStringFromServer()
    Local $a = Random(1,10,1)
    If Mod($a, 2) = 0 Then
        Return ""
    Else
        Return "String"
    EndIf
EndFunc

Thats not exactly what I want. I basiccly like to have a loop which can never end.

So in the loop is a if statement, String recieved or not, but in all cases the loop must wait a few seconds and then start again.

In your case the loop will exit when False is returned?


Share this post


Link to post
Share on other sites
Jfish

AdlibRegister("_folderListen",5000); call the function every 5 seconds


func _folderListen()
ConsoleWrite("checking for files"&@crlf); show that you are checking on the console
if FileExists(@ScriptDir&"\testfolder\*.txt") Then ; look for a text file in the folder
    MsgBox("","","File located")
EndIf
EndFunc

while 1 ; keeps the process running forever

WEnd

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

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  

×