Jump to content

If...EndIf Help!


 Share

Recommended Posts

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

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

Link to comment
Share on other sites

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