Jump to content

Need help with making script smaller


 Share

Recommended Posts

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:

#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 by likevvii
Link to comment
Share on other sites

  • Moderators

Hi,

To follow up the "not a game" plea - please see my post here. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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