Sign in to follow this  
Followers 0
insanity

Loop Statements

7 posts in this topic

I am trying to makes the following code to loop until it kills the creature in the game it is for.

The 'you aim for A' is the first attack. then after the first attack if the omnster has not been kill it gives a message 'You attack A' until the monster has died. When the monster dies you get a 'Enemy is Dead, R.I.P.' messge.

I am trying to make the script continually click the button until the Enemy id dead message appears, and then to re run the entire script again. Any help would be appreciated.

#region --- ScriptWriter generated code Start ---

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

WinWait("Shimlar - Microsoft Internet Explorer","")

If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")

WinWaitActive("Shimlar - Microsoft Internet Explorer","")

MouseMove(957,382)

MouseDown("left")

MouseMove(330,118)

MouseUp("left")

Sleep(1000)

#endregion --- ScriptWriter generated code End ---

If 'You aim for A' Then

#region --- ScriptWriter generated code Start ---

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

WinWait("Shimlar - Microsoft Internet Explorer","")

If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")

WinWaitActive("Shimlar - Microsoft Internet Explorer","")

MouseMove(551,220)

MouseDown("left")

MouseUp("left")

Sleep(1000)

#endregion --- ScriptWriter generated code End ---

ElseIf 'You attack A' Then

#region --- ScriptWriter generated code Start ---

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

WinWait("Shimlar - Microsoft Internet Explorer","")

If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")

WinWaitActive("Shimlar - Microsoft Internet Explorer","")

MouseMove(551,220)

MouseDown("left")

MouseUp("left")

Sleep(1000)

#endregion --- ScriptWriter generated code End ---

If 'Enemy is dead, R.I.P.' Then

#region --- ScriptWriter generated code Start ---

Opt("WinWaitDelay",100)

Opt("WinTitleMatchMode",4)

Opt("WinDetectHiddenText",1)

Opt("MouseCoordMode",0)

WinWait("Shimlar - Microsoft Internet Explorer","")

If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")

WinWaitActive("Shimlar - Microsoft Internet Explorer","")

MouseMove(786,184)

MouseDown("left")

MouseUp("left")

Sleep(1000)

#endregion --- ScriptWriter generated code End ---

Thanks

Share this post


Link to post
Share on other sites



Here's an endless loop :)

While 1
WEnd

My UDFs: ExitCodes

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I can only guess you mean something like this.

The first while 1 loops the entire code all the way down to the bottom Wend

The second while 1 loops through the section of code untill the Wend immediately after the thing is dead, the exitloop makes it jump out of the inner loop back in to the main loop.

While 1

#region --- ScriptWriter generated code Start --- 
Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Shimlar - Microsoft Internet Explorer","")
If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")
WinWaitActive("Shimlar - Microsoft Internet Explorer","")
MouseMove(957,382)
MouseDown("left")
MouseMove(330,118)
MouseUp("left")
Sleep(1000)
#endregion --- ScriptWriter generated code End --- 

    While 1
        If 'You aim for A' Then 

        #region --- ScriptWriter generated code Start --- 
        Opt("WinWaitDelay",100)
        Opt("WinTitleMatchMode",4)
        Opt("WinDetectHiddenText",1)
        Opt("MouseCoordMode",0)
        WinWait("Shimlar - Microsoft Internet Explorer","")
        If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")
        WinWaitActive("Shimlar - Microsoft Internet Explorer","")
        MouseMove(551,220)
        MouseDown("left")
        MouseUp("left")
        Sleep(1000)
        #endregion --- ScriptWriter generated code End --- 

            ElseIf 'You attack A' Then

            #region --- ScriptWriter generated code Start --- 
            Opt("WinWaitDelay",100)
            Opt("WinTitleMatchMode",4)
            Opt("WinDetectHiddenText",1)
            Opt("MouseCoordMode",0)
            WinWait("Shimlar - Microsoft Internet Explorer","")
            If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")
            WinWaitActive("Shimlar - Microsoft Internet Explorer","")
            MouseMove(551,220)
            MouseDown("left")
            MouseUp("left")
            Sleep(1000)
        #endregion --- ScriptWriter generated code End --- 
        If 'Enemy is dead, R.I.P.' Then exitloop
endif;<<<< that was missing and is why it wasn't working
    Wend

#region --- ScriptWriter generated code Start --- 
Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Shimlar - Microsoft Internet Explorer","")
If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")
WinWaitActive("Shimlar - Microsoft Internet Explorer","")
MouseMove(786,184)
MouseDown("left")
MouseUp("left")
Sleep(1000)
#endregion --- ScriptWriter generated code End ---
Wend
Edited by ChrisL

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

There was an Endif missing above the first Wend.

While 1

#region --- ScriptWriter generated code Start --- 
Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Shimlar - Microsoft Internet Explorer","")
If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")
WinWaitActive("Shimlar - Microsoft Internet Explorer","")
MouseMove(957,382)
MouseDown("left")
MouseMove(330,118)
MouseUp("left")
Sleep(1000)
#endregion --- ScriptWriter generated code End --- 

    While 1
        If 'You aim for A' Then 

        #region --- ScriptWriter generated code Start --- 
        Opt("WinWaitDelay",100)
        Opt("WinTitleMatchMode",4)
        Opt("WinDetectHiddenText",1)
        Opt("MouseCoordMode",0)
        WinWait("Shimlar - Microsoft Internet Explorer","")
        If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")
        WinWaitActive("Shimlar - Microsoft Internet Explorer","")
        MouseMove(551,220)
        MouseDown("left")
        MouseUp("left")
        Sleep(1000)
        #endregion --- ScriptWriter generated code End --- 

            ElseIf 'You attack A' Then

            #region --- ScriptWriter generated code Start --- 
            Opt("WinWaitDelay",100)
            Opt("WinTitleMatchMode",4)
            Opt("WinDetectHiddenText",1)
            Opt("MouseCoordMode",0)
            WinWait("Shimlar - Microsoft Internet Explorer","")
            If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")
            WinWaitActive("Shimlar - Microsoft Internet Explorer","")
            MouseMove(551,220)
            MouseDown("left")
            MouseUp("left")
            Sleep(1000)
        #endregion --- ScriptWriter generated code End --- 
        If 'Enemy is dead, R.I.P.' Then exitloop
        Endif
    Wend

#region --- ScriptWriter generated code Start --- 
Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWait("Shimlar - Microsoft Internet Explorer","")
If Not WinActive("Shimlar - Microsoft Internet Explorer","") Then WinActivate("Shimlar - Microsoft Internet Explorer","")
WinWaitActive("Shimlar - Microsoft Internet Explorer","")
MouseMove(786,184)
MouseDown("left")
MouseUp("left")
Sleep(1000)
#endregion --- ScriptWriter generated code End ---
Wend
Edited by ChrisL

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I am trying to makes the following code to loop until it kills the creature in the game it is for.

:) Here's another example:

Posted Image

Edited by tonedeaf

Share this post


Link to post
Share on other sites

I have a question...

These 3 If/ElseIf statements:

If 'You aim for A' Then

And

ElseIf 'You attack A' Then

And

If 'Enemy is dead, R.I.P.' Then exitloop

I suppose your going to make a command for those right?.... like:

If ControlGetText('WindowName', '', 100) = 'Enemy is dead, R.I.P.' Then
   ;Do Something
EndIf
The ControlGetText is just an example of finding out if the "Conditional" statement is true or not. If your not using a correct conditional statement, then the rest is really null and void.

Also, if your going to keep your "Opt(s)" all the same, there is no need to keep repeating them.... Once would be enough at the top of your script.

Here is an example of what it looks to me that you are trying to accomplish:

#region --- ScriptWriter generated code Start ---
Global $WinName = "Shimlar - Microsoft Internet Explorer"
Global $PopUp_Window_Name = 'Whatever the title of the PopUp that you want to get commands from'
Opt("WinWaitDelay",100)
Opt("WinTitleMatchMode",4)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)
WinWaitFunc()
MouseClick('left', 957, 382)
MouseClick('left', 330, 118)
Sleep(1000)
#endregion --- ScriptWriter generated code End ---

While 1
    If StringInStr(WinGetText($PopUp_Window_Name), 'You aim for A') Then; StringInStr() and WinGetText Just an example of Conditional
        WinWaitFunc(); just made a function for this since you are using it so much (winwait()/WinActivate()/WinWaitActive()
        MouseClick('left', 551, 220)
        Sleep(1000)
    ElseIf StringInStr(WinGetText($PopUp_Window_Name), 'You attack A') Then
        WinWaitFunc()
        MouseClick('left', 551, 220)
        Sleep(1000)
    ElseIf StringInStr(WinGetText($PopUp_Window_Name), 'Enemy is dead, R.I.P.') Then
        WinWaitFunc()
        MouseClick('left', 786, 184)
        Sleep(1000)
    EndIf
WEnd

Func WinWaitFunc()
    WinWait($WinName)
    If Not WinActive($WinName) Then WinActivate($WinName)
    WinWaitActive($WinName)
EndFunc

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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