Jump to content
Sign in to follow this  
jafuuu

If...EndIf Help!

Recommended Posts

jafuuu

Hi, Im working whit _IE and an internet web-browsing game, somethimes, when I click in a button incluided in the game (flash button) after the page load I can see a message in the page saying "An unexpected error has occurred" or "Under maintenance", so I make 2 If..Then statements (You can see it in the source), but I need to check taht statements in every step than make the loop, any solution?

$name = IniRead(@ScriptDir&"\Options.ini", "GENERAL", "NAME", "")
$server = IniRead(@ScriptDir&"\Options.ini", "GENERAL", "SERVER", "")

Opt("WinTitleMatchMode", 2) 
$oIE = _IECreate ("http://"&$name&"."&$server&"/")
_IELoadWait ($oIE)
$text = _IEBodyReadText ($oIE)

If StringInStr($text,"An unexpected error has occurred") Then
 While StringInStr($text,"An unexpected error has occurred")
 Send ("{F5}")
 Sleep (5000)
 Wend
EndIf
 
If StringInStr($text,"Under maintenance") Then
 While StringInStr($text,"Under maintenance")
 SplashTextOn ("Pause","Under maintenance...",300,50) 
 Sleep (600000)
 SplashOff ()
 Sleep (1000)
 Send ("{F5}")
Wend 
EndIf

While 1
;Irrelevant Statements, some _IENavigate and mouseclicks
Wend

Share this post


Link to post
Share on other sites
exodius

Put your If...EndIf Statements in a function and just call the function over and over:

$name = IniRead(@ScriptDir & "\Options.ini", "GENERAL", "NAME", "")
$server = IniRead(@ScriptDir & "\Options.ini", "GENERAL", "SERVER", "")

Opt("WinTitleMatchMode", 2)
$oIE = _IECreate("http://" & $name & "." & $server & "/")
_IELoadWait($oIE)
_Check()

While 1
    ;Irrelevant Statements, some _IENavigate and mouseclicks
WEnd


Func _Check()
    $text = _IEBodyReadText($oIE)

    If StringInStr($text, "An unexpected error has occurred") Then
        While StringInStr($text, "An unexpected error has occurred")
            Send("{F5}")
            Sleep(5000)
        WEnd
    EndIf

    If StringInStr($text, "Under maintenance") Then
        While StringInStr($text, "Under maintenance")
            SplashTextOn("Pause", "Under maintenance...", 300, 50)
            Sleep(600000)
            SplashOff()
            Sleep(1000)
            Send("{F5}")
        WEnd
    EndIf
EndFunc

Based on my example, everywhere you would use the If...EndIf statements, just put _Check().

Share this post


Link to post
Share on other sites
jafuuu

Put your If...EndIf Statements in a function and just call the function over and over:

$name = IniRead(@ScriptDir & "\Options.ini", "GENERAL", "NAME", "")
$server = IniRead(@ScriptDir & "\Options.ini", "GENERAL", "SERVER", "")

Opt("WinTitleMatchMode", 2)
$oIE = _IECreate("http://" & $name & "." & $server & "/")
_IELoadWait($oIE)
_Check()

While 1
    ;Irrelevant Statements, some _IENavigate and mouseclicks
WEnd


Func _Check()
    $text = _IEBodyReadText($oIE)

    If StringInStr($text, "An unexpected error has occurred") Then
        While StringInStr($text, "An unexpected error has occurred")
            Send("{F5}")
            Sleep(5000)
        WEnd
    EndIf

    If StringInStr($text, "Under maintenance") Then
        While StringInStr($text, "Under maintenance")
            SplashTextOn("Pause", "Under maintenance...", 300, 50)
            Sleep(600000)
            SplashOff()
            Sleep(1000)
            Send("{F5}")
        WEnd
    EndIf
EndFunc

Based on my example, everywhere you would use the If...EndIf statements, just put _Check().

somebody tells you, u r like a god?

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.