Sign in to follow this  
Followers 0
dorochet

What would be more efficient code?

3 posts in this topic

#1 ·  Posted (edited)

Ok so below is part of a program I have written that opens a game client and runs a few actions by clicking and sending input. This is just a small part of the program, and its just more of the same, LOTS MORE. I was wondering if anyone had any better ideas to make this cleaner, perhaps more efficient. I am also including a picture of the game client to show you what I am looking at when coding this.

;Add Housing
MouseClick("left",100,650,1,10);First Box
Sleep(500)
MouseClick("left",100,525,1,10);Add Structures (up to)
Sleep(500)
MouseClick("left",250,650,1,10);Second Box
Sleep(500)
MouseClick("left",250,480,1,10);House Complex
Sleep(500)
MouseClick("left",400,650,1,10);3rd Box
Sleep(500)
MouseClick("left",400,675,1,10);Always
Sleep(500)
MouseClick("left",350,650,1,10);Input Box 1
Sleep(500)
Send("{BACKSPACE}{BACKSPACE}{DELETE}{DELETE}")
Send("5")
Sleep(500)
MouseClick("left",230,680,1,10);Apply Now!
Sleep(500)

Posted Image

I have thought of doing the following

Local $XYCoords[2][10]

For $i=o to 10 step 1
Mouseclick($XYCoords[0][i],$XYCoords[1][i])
Sleep(500)
Switch $i
  Case i ==8
      Send(Keystrokes)
  Case i ==10
      Send(MoreKeystrokes)

So I would put all of the xy coordinates into an array and just cycle through them with a loop, using a switch case to send keystrokes when needed. Sadly, if I just initalize the array $XYCoords[2][10] = [1,2,3....,10][1,2,3....,10] the labels of each coordinate go away and make it hard to edit. I was also thinking maybe make the list in Excel, and read the values into the array, which might make it more editable.

Bottom line is I think the code is terrible to read for me, nevermind anyone else, so I am looking for a better way to do things.

Edited by dorochet

Share this post


Link to post
Share on other sites



It wont make it any neater or easy to read but,

think about using ControlClick and ControlSend if you can

And to make it more efficient if the screen changes after every time you click some thing do a pixelsearch to make sure that it did it so that it doesnt fail because your computer was trying to do something in another program and may have lagged it a little bit

Share this post


Link to post
Share on other sites

I have thought of doing the following

Local $XYCoords[2][10]

For $i=o to 10 step 1
Mouseclick($XYCoords[0][i],$XYCoords[1][i])
Sleep(500)
Switch $i
  Case i ==8
      Send(Keystrokes)
  Case i ==10
      Send(MoreKeystrokes)

So I would put all of the xy coordinates into an array and just cycle through them with a loop, using a switch case to send keystrokes when needed. Sadly, if I just initalize the array $XYCoords[2][10] = [1,2,3....,10][1,2,3....,10] the labels of each coordinate go away and make it hard to edit. I was also thinking maybe make the list in Excel, and read the values into the array, which might make it more editable.

Not sure what you mean by "labels of each coordinate go away and make it hard to edit," but this code will do what I think you were trying to accomplish with the array. In your code example you're missing the Next and EndSwitch, and you're using the letter o instead of number 0. You'll note that I removed the last parameter from your MouseClick() command since 10 is the default speed if a value is not specified. You can also look up any of the commands I use in the Help file and I'd suggest using SciTE4AutoIt3 since it comes with many cool tools to help noobs plus checks for syntax errors.

;Add Housing
Local $aH[7][4] = [["left", 100, 650, 1], ["left", 100, 525, 1], ["left", 250, 650, 1], ["left", 250, 480, 1], _
        ["left", 400, 650, 1], ["left", 400, 675, 1], ["left", 350, 650, 1]]

For $i = 0 To UBound($aH, 1) - 1
    MouseClick($aH[$i][0], $aH[$i][1], $aH[$i][2], $aH[$i][3])
    Sleep(500)
Next

Send("{BACKSPACE 2}{DELETE 2}5")
Sleep(500)
MouseClick("left", 230, 680, 1, 10);Apply Now!
Sleep(500)

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