Jump to content

Functions with Arrays?


Recommended Posts

newbY Round 2. So I'm trying to get this array Click[$n]() to use a specific function command depending on the value of [$n], but I guess that's not how it's designed to work. Any ideas?

Here's my code:

$Click = "Click1(),Click2(),Click3()"

Dim $Split[3]
$Split = StringSplit($Click,",")

For $n = 1 to 3
sleep(1000)
Click[$n]
Next

Func Click1()
    MouseClick("left", 858, 500)
EndFunc

Func Click2()
MouseClick("left", 858, 550)
EndFunc

Func Click3()
MouseClick("left", 858, 600)
EndFunc
Link to comment
Share on other sites

This largely depends on what you want it to do, but here are some possible answers:

Just have one function, and have a parameter- so it would be like

Func Click($n)
   MouseClick("left", 858, 500 + (50 * $n))
EndFunc

This doesn't use the arrays at all, but I don't know if your goal was to figure out a way to use the arrays to do this, or maybe you were just trying to figure out another way to run the function there. But if you did want to be able to use arrays to do this, what RichardL said about the call function should work. I haven't had to use that before either, but looking in the helpfile, hopefully this might work:

For $n = 0 To 2 Step 1
Sleep(1000)
Call($Click[$n])
Next

Hope it helped

:)

Edit: using the 'call' method didn't work when I tried it in scite, but just laying out the $Click array made it work. Maybe I did something wrong and accidentally changed something in one of the functions, but here is a quick copy and paste from what did make it work:

Global $Click[3]
$Click[0] = "Click1"
$Click[1] = "Click2"
$Click[2] = "Click3"
Edited by mischieftoo
Link to comment
Share on other sites

Hey Guys, Thx! The "Call" did the trick. But now I've run into another problem, I can't put it into a Do Until or While 1 Wend loop. :)

How can I loop this:

For $n = 0 To 2 Step 1
Sleep(1000)
Call($Click[$n])
Next

Also, what I have so far:

HotKeySet("{ESC}" , "quit")

Global $Click[3]

$Click[0] = Click1()
$Click[1] = Click2()
$Click[2] = Click3()


For $n = 0 To 2 Step 1
Sleep(1000)
Call($Click[$n])
Next



Func Click1()
    MouseClick("left", 858, 400)
EndFunc

Func Click2()
    MouseClick("left", 858, 650)
EndFunc

Func Click3()
    MouseClick("left", 858, 200)
EndFunc

Func quit()
    Exit 1
EndFunc
Link to comment
Share on other sites

Well, back to the drawing board. The Call command doesn't really work, and that's why I couldn't get it to loop.

Newb mistake but defining the Clicks[0] made the mouse move&click and not the Call line. DOH :/

This:

Global $Click[3]
$Click[0] = "Click1"
$Click[1] = "Click2"
$Click[2] = "Click3"

The answer might be the Call command, going to check it out more tomorrow. time for sleep

Link to comment
Share on other sites

I'm not sure what your referring to, but i think you are saying that typing out Clicks[0] is going to make the mouse click? The regular functions use the pathentesis ( ) to fill in parameters, not the brackets [ ]. But i dont get what you were saying, because when i ran it as i posted, scite showed no errors? It should be working fine.

But when you said the call command doesnt really work, could you explain? It might be that you defined the strings with the parenthesis at the end, which i think you did earlier up there; that might be the cause of an error. Meaning, instead of

"click1()"

Use

"click1"

Link to comment
Share on other sites

I'm not sure what your referring to, but i think you are saying that typing out Clicks[0] is going to make the mouse click? The regular functions use the pathentesis ( ) to fill in parameters, not the brackets [ ]. But i dont get what you were saying, because when i ran it as i posted, scite showed no errors? It should be working fine.

But when you said the call command doesnt really work, could you explain? It might be that you defined the strings with the parenthesis at the end, which i think you did earlier up there; that might be the cause of an error. Meaning, instead of

"click1()"

Use

"click1"

Link to comment
Share on other sites

if you need only mouse click this can help

HotKeySet('{ESC}','_exit')
Dim $Split[3][2] = [[858, 500],[858, 550],[858, 600]]
While 1
    For $n = 0 to UBound($Split)-1
        sleep(1000)
        MouseClick("left",$Split[$n][0],$Split[$n][1])
    Next
WEnd
Func _exit()
    Exit
EndFunc

if you use mouseclick only as example and you need something else in your funcs then mischieftoo geaved you nice solution

HotKeySet('{ESC}','_exit')
;~ $Split = StringSplit("Click1,Click2,Click3",",")
Dim $Split[3] = ['Click1','Click2','Click3']
While 1
    For $n = 0 to UBound($Split)-1
        sleep(1000)
        Call($Split[$n])
    Next
WEnd

Func Click1()
    MouseClick("left", 858, 500)
EndFunc
Func Click2()
    MouseClick("left", 858, 550)
EndFunc
Func Click3()
    MouseClick("left", 858, 600)
EndFunc
Func _exit()
    Exit
EndFunc

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

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