likevvii Posted January 11, 2014 Share Posted January 11, 2014 (edited) How could I shrink my script using variables or other methods? I have a simple script with some (ImageSearch, mouseclick, send), and two variables for the ImageSearches. 1.bmp, 2.bmp, 3.bmp, etc... 1a.bmp, 1b.bmp, 3.bmp, etc... are my changing values. Here is some of the script: expandcollapse popup#include <ImageSearch.au3> HotKeySet("{HOME}", "Start") HotKeySet("{ESC}", "kill") Func kill() Exit 0 EndFunc $X = 0 $Y = 0 $speed = 1 Func Start() $Search1 = _ImageSearch('1.bmp', 0, $X, $Y, 0) ; (1.bmp) is the variable If $Search1 = 1 Then MouseClick( "left", $X+40, $Y+8, 3, $speed) Send( "{CTRLDOWN}" ) Send( "c" ) Send( "{CTRLUP}" ) WinActivate ( "autoscript" ) $Search = _ImageSearch('1a.bmp', 0, $X, $Y, 0) ; (1a.bmp) is the other variable If $Search = 1 Then MouseClick( "left", $X+75, $Y+5, 1, $speed) Send( "{ALT}" ) Send( "h" ) Send( "v" ) Send( "m" ) EndIf EndIf Sleep( 0 ) $Search2 = _ImageSearch('2.bmp', 0, $X, $Y, 0) If $Search2 = 1 Then MouseClick( "left", $X+40, $Y+8, 3, $speed) Send( "{CTRLDOWN}" ) Send( "c" ) Send( "{CTRLUP}" ) WinActivate ( "autoscript" ) $Search = _ImageSearch('1b.bmp', 0, $X, $Y, 0) If $Search = 1 Then MouseClick( "left", $X+75, $Y+5, 1, $speed) Send( "{ALT}" ) Send( "h" ) Send( "v" ) Send( "m" ) EndIf EndIf Sleep( 0 ) $Search2 = _ImageSearch('3.bmp', 0, $X, $Y, 0) If $Search2 = 1 Then MouseClick( "left", $X+40, $Y+8, 3, $speed) Send( "{CTRLDOWN}" ) Send( "c" ) Send( "{CTRLUP}" ) WinActivate ( "autoscript" ) $Search = _ImageSearch('1c.bmp', 0, $X, $Y, 0) If $Search = 1 Then MouseClick( "left", $X+75, $Y+5, 1, $speed) Send( "{ALT}" ) Send( "h" ) Send( "v" ) Send( "m" ) EndIf EndIf Sleep( 0 ) $Search2 = _ImageSearch('4.bmp', 0, $X, $Y, 0) If $Search2 = 1 Then MouseClick( "left", $X+40, $Y+8, 3, $speed) Send( "{CTRLDOWN}" ) Send( "c" ) Send( "{CTRLUP}" ) WinActivate ( "autoscript" ) $Search = _ImageSearch('1d.bmp', 0, $X, $Y, 0) If $Search = 1 Then MouseClick( "left", $X+75, $Y+5, 1, $speed) Send( "{ALT}" ) Send( "h" ) Send( "v" ) Send( "m" ) EndIf EndIf Sleep( 0 ) $Search2 = _ImageSearch('5.bmp', 0, $X, $Y, 0) If $Search2 = 1 Then MouseClick( "left", $X+40, $Y+8, 3, $speed) Send( "{CTRLDOWN}" ) Send( "c" ) Send( "{CTRLUP}" ) WinActivate ( "autoscript" ) $Search = _ImageSearch('1e.bmp', 0, $X, $Y, 0) If $Search = 1 Then MouseClick( "left", $X+75, $Y+5, 1, $speed) Send( "{ALT}" ) Send( "h" ) Send( "v" ) Send( "m" ) EndIf EndIf Sleep( 0 ) $Search2 = _ImageSearch('6.bmp', 0, $X, $Y, 0) If $Search2 = 1 Then MouseClick( "left", $X+40, $Y+8, 3, $speed) Send( "{CTRLDOWN}" ) Send( "c" ) Send( "{CTRLUP}" ) WinActivate ( "autoscript" ) $Search = _ImageSearch('1f.bmp', 0, $X, $Y, 0) If $Search = 1 Then MouseClick( "left", $X+75, $Y+5, 1, $speed) Send( "{ALT}" ) Send( "h" ) Send( "v" ) Send( "m" ) EndIf EndIf Sleep( 0 ) .....etc goes on to 12..... While 1 sleep(100) Wend I tried to do: $first = "1.bmp" $second = "1a.bmp" But that totally failed. I added ( ) [ ] ' ', and anything I could think of, but it never works. Since I will need to do about 120 of these codes later on, i was thinking if there is a way where i can shrink the body of the script? Func Start() $Search1 = _ImageSearch('first variable', 0, $X, $Y, 0) If $Search1 = 1 Then MouseClick( "left", $X+40, $Y+8, 3, $speed) Send( "{CTRLDOWN}" ) Send( "c" ) Send( "{CTRLUP}" ) WinActivate ( "autoscript" ) $Search = _ImageSearch('second variable', 0, $X, $Y, 0) If $Search = 1 Then MouseClick( "left", $X+75, $Y+5, 1, $speed) Send( "{ALT}" ) Send( "h" ) Send( "v" ) Send( "m" ) EndIf EndIf to seomthing like: savedscript "first variable" "second variable" ;name savedscript "first variable" "second variable" ;name savedscript "first variable" "second variable" ;name savedscript "first variable" "second variable" ;name savedscript "first variable" "second variable" ;name savedscript "first variable" "second variable" ;name ......x120 I know this is a garbage attempt. But I seriously looked as hard as I could on google for ways to "shrink script" THIS IS NOT FOR A ANYGAME OF ANY SORT. I know imagesearch is very suspicious for use in a game. This is for copying data from a chart to an excel document. Edited January 11, 2014 by likevvii Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 11, 2014 Moderators Share Posted January 11, 2014 Hi,To follow up the "not a game" plea - please see my post here. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now