Locked Home » Forums » Legacy & Archived » Archived Content » Star Wars Galaxies » SWG Premium Discussions

AutoIt helper functions : SWG Premium Discussions

Posted: March 4th, 2010
User avatar
Total Posts:387 Joined:2009
I was bored recently and got annoyed when making a new script (Chronicler xp macro, when I work out a last few bugs I'll post it), and made a bunch of helper functions to reduce all the annoying typing, the au3 file to include is attached to this post.
Inclusion can be done by simply copying its contents to the top of your current script, or save this as, for example, functions.au3 in the same directory and using

Code: Register to unlock hidden link

#include "functions.au3"
In the top of your script.


Now, you may ask, what does this do?
It automatically sets the end key to terminate the running script.

And it adds a bunch of functions, which I will describe here, in this pattern
returnValue FunctionName ( argumentType $argumentName, argumentType $argumentName2 [, argumentType $optionalArgument=defaultValue ] )

Void as returnValue means that there is none.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void notify ( string $description )
This function is a shorthand alias for

Code: Register to unlock hidden link

ToolTip($description,10,10,"",0,1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

array getPos ( string $description, int $heyKey )
This function gets the position of the location of the cursor when hexKey is pressed, and returns the array for extraction of X/Y coordinates or passing them along to the Click function.
Description is used with notify for telling the user on what to do.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

array getLeftClick ( string $description )
array getRightClick ( string $description )
array getShiftPress ( string $description )
Helper functions for getPos, should be self explanatory

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void click ( array $xyArray [, int $clicks=1 ] [, string $button="left" ] [, int $pause = 300 ] )
This function clicks an area of the screen with the coordinates stored in $xyArray in pattern:
$xyArray[0] = $xCoord
$xyArray[1] = $yCoord

Designed to be used with the getPos function. $pause parameter is the sleep done after the click.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

mixed getInput ( string $title, string $description, string $regexpTest [, int $exitOnCancel=1 ] [, string $default='' ] [, int $width='' ] [, int $height='' ] )
This function gives an input prompt with title $title and text $description. $regexpTest is a regular expression to match the input against to see if it is valid. If you don't know regular expressions, I suggest to ignore this function. They're somewhat of a headache to learn. If you do know them, this function should not be explained further.




Examples:
Example 1: Ask the user for a location on the screen, wait 5 seconds and then double click it.

Code: Register to unlock hidden link

$loc = getLeftClick("What location should I double click in 5 seconds? Please leftclick that location once.")
sleep(5000)
click($loc, 2)
notify("Clicked said location twice. Ending script in 5 seconds.")
sleep(5000)
notify("")
Example 2: Ask the user for a number. If user presses cancel the script will stop.

Code: Register to unlock hidden link

$number = getInput("Choose a number", "Please enter a number", "^[0-9]*$")
msgbox(0, "Chosen number", "You chose " & $number)



Footnotes
If you have suggestions/requests for functions please post them and I will consider including them in future versions. Besides that: Any input is very welcome.


Attachments:
functions.txt Register to unlock hidden link
v1.0
(1.54 KiB) Downloaded 19 times
Posted: March 4th, 2010
User avatar
Total Posts:1872 Joined:2006
Yays or Nays please.

_________________
Your Friendly Neighborhood Moderator!
Read The FAQ - Register to unlock hidden link
Posted: March 5th, 2010
User avatar
Total Posts:1087 Joined:2007
vinnyboy32 wrote:Yays or Nays please.
wat? I have no idea what he is trying to provide.
Posted: March 6th, 2010
User avatar
Total Posts:387 Joined:2009
cuervogold wrote:
vinnyboy32 wrote:Yays or Nays please.
wat? I have no idea what he is trying to provide.
Ever wrote an autoit script? Usually people write them cluttered and, well, stupid. I just suggest using these functions for making scripts... Ill provide a difference in code later
Posted: March 6th, 2010
User avatar
Total Posts:1087 Joined:2007
r04r wrote:
cuervogold wrote:
vinnyboy32 wrote:Yays or Nays please.
wat? I have no idea what he is trying to provide.
Ever wrote an autoit script? Usually people write them cluttered and, well, stupid. I just suggest using these functions for making scripts... Ill provide a difference in code later

I've written many AutoIt scripts, most of which are here. I wrote one of the frist RE scripts.
Posted: March 6th, 2010
User avatar
Total Posts:387 Joined:2009
cuervogold wrote:
r04r wrote:
cuervogold wrote: wat? I have no idea what he is trying to provide.
Ever wrote an autoit script? Usually people write them cluttered and, well, stupid. I just suggest using these functions for making scripts... Ill provide a difference in code later

I've written many AutoIt scripts, most of which are here. I wrote one of the frist RE scripts.
Alright, I didn't mean to be insulting/rude by the way. But here's an example of what I mean.

A piece of your code:

Code: Register to unlock hidden link

SplashTextOn("Auto RE setup", "Please Click once on the center of the main RE tool. ", 400, 100, -1, -1, 0, "Ariel", 15); = this is B
While 1
Sleep ( 100 )
If _IsPressed("01") Then
$pos = MouseGetPos()
ExitLoop
EndIf
WEnd
SplashOff()
$mainre1x = $pos[0]
$mainre1y = $pos[1]
Sleep ( 1000 )

SplashTextOn("Auto RE setup", "Please Click once on the center of the mod bit RE tool. ", 400, 100, -1, -1, 0, "Ariel", 15) ; = this is C
While 1
Sleep ( 100 )
If _IsPressed("01") Then
$pos = MouseGetPos()
ExitLoop
EndIf
WEnd
SplashOff()
$modbittoolx = $pos[0]
$modbittooly = $pos[1]
Sleep ( 1000 )
And what it could be:

Code: Register to unlock hidden link

$mainre1 = getLeftClick("Please Click once on the center of the main RE tool.")
$modbittool = getLeftClick("Please Click once on the center of the mod bit RE tool.")
Then later on in the code to right click the $mainre1

Code: Register to unlock hidden link

click($mainre1, 1, "right")

I'm not saying my code is perfect because I realize that some of the XY arrays need offsets and such, but I would like to encourage people to use functions more often to handle a code snipper instead of reusing it over and over again. This is a more effective way of coding, and easier to scroll through too.


I didn't expect to get any points for this anyway, I'm just trying to provide some insight on how to effectively use functions, and how it would help making things easier.

Also for people who don't really know autoit, this would be a massive help for instead of using the 12 lines of code to grab an XY coord of a moues click, turning it into one line.

~Just what I see to be useful
Posted: March 8th, 2010
User avatar
Total Posts:1087 Joined:2007
I'll keep using my cluttered and stupid scripts, thanks.
Posted: March 8th, 2010
User avatar
Total Posts:387 Joined:2009
cuervogold wrote:I'll keep using my cluttered and stupid scripts, thanks.
Hey, no offense intended at all. I'm just saying that the writing could be easier. Especially for people who are starting out for AutoIt.
Also I never said that your scripts were stupid, quite the opposite actually. The way of making them is a little stupid, because it could be done much easier. That's all.
If you're taking offense I apologize for that, because that certainly wasn't my intention.

I hope that some other people will see the use for this, and if not I suppose I'll just keep it for my own advantage.
Ready to join the community? Click here and see all of the benefits!
blue large dotWho is online
Users browsing this forum: No registered users and 3 guests
Locked