Jump to content

Starting a function at start, list/conditional question


ponchato
 Share

Recommended Posts

Hey everyone.

This is a script for clicking through some bookmarks. I could just, you know, use my mouse, but where's the fun in that? It does work, I'm just wondering how to... streamline it.

First, the script presses the 'g' key at the beginning to start the "Go" function. Can I get it to start the "Go" function when I start the script without making it press 'g'?

Second, I'm willing to bet that there's a much more efficient way to go through each of the mouse clicks than the huge list of 'ElseIf' commands.

I'm just asking because I want to see how I can write scripts more efficiently; this script by itself isn't exactly a challenge.

Global $spot = 1
HotKeySet ("{g}", "Go")
Send ( "{g}")

Func Go()
    If $spot = 1 Then
        MouseClick ( "left", 80, 880, 1, 2)
        WinWait ("Google")
        MouseClick ( "left", 315, 90, 1, 2)
        $spot = 2
    ElseIf $spot = 2 Then
        MouseClick ("left", 10, 65)
        WinWait ("The Escapist")
        $spot = 3
    ElseIf $spot = 3 Then
        MouseClick ("left", 30, 65)
        WinWait ("MLG")
        $spot = 4
    ElseIf $spot = 4 Then
        MouseClick ("left", 75, 65)
        WinWait ("Scottsdale")
        $spot = 5
    ElseIf $spot = 5 Then
        MouseClick ("left", 95, 65)
        WinWait ("Arizona")
        $spot = 6
    ElseIf $spot = 6 Then
        MouseClick ("left", 125, 65)
        WinWait("Business")
        $spot = 7
    EndIf
EndFunc

While $spot <> 7
    Sleep (100)
WEnd

If $spot = 7 Then
EndIf

I may or may not have to explain this, I don't know: the $spot variable and having everything in a... uh, "Func" function are so that the script waits for me to press 'g' while I look at a page, then continues. After the last page, it ends the script.

Edited by ponchato
Link to comment
Share on other sites

Untested

Global $spot = 1

Go()

Func Go()
    local $aspot[6][3] = [[1,"Google",80,40],[2,"The Escapist",10,65],[3,"MLG",30,65], _
    [4,"Scottsdale",75,65],[5,"Arizona",95,65],[6,"Business",125,65]]
    For $i = 0 To UBound($aspot)-1
        If $spot = $aspot[$i][0] Then
            MouseClick ("left", $aspot[$i][2], $aspot[$i][3])
            WinWait ($aspot[$i][1])
            $spot = $i +1
        EndIf
EndFunc     


While $spot <> 7
    Sleep (100)
WEnd

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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