I have created a small function that clicks a certain portion of the screen. It will be used but clicked a different number of times throughout the program. I would like to be able to input the amount of clicks as a parameter, however, when I try to do this rather than hard coding the amount of loops that part of the code does not run and the screen does not get clicked.
Note changes to function ClickMainBuilding in definition and as it's called below
Here is what works:
; ######## SETTINGS ########
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1
; ######## FUNCTIONS ########
ClickMainBuilding(){
Loop, 5
{
Click, 927, 538 Left, , Down
Sleep, 250
Click, 927, 538 Left, , Up
Sleep, 250
}
}
ClickTradeDepot(){
Click, 420, 705
Sleep, 750
}
ExitTradeDepot(){
Click, 1512, 129
Sleep, 750
}
^!u:: ; ### MAIN ###
WinActivate, ahk_class ThumbnailDeviceHelperWnd
Sleep, 333
WinActivate, BlueStacks ahk_class HwndWrapper[Bluestacks.exe;;5b32fde4-2355-48c5-be51-8927697e9914]
Sleep, 500
ClickMainBuilding()
Sleep, 1000
ClickTradeDepot()
Sleep, 1000
ExitTradeDepot()
Return
Esc::ExitApp ; Exit script with Escape key
Here is what doesn't:
; ######## SETTINGS ########
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1
; ######## FUNCTIONS ########
ClickMainBuilding(x){
Loop, x
{
Click, 927, 538 Left, , Down
Sleep, 250
Click, 927, 538 Left, , Up
Sleep, 250
}
}
ClickTradeDepot(){
Click, 420, 705
Sleep, 750
}
ExitTradeDepot(){
Click, 1512, 129
Sleep, 750
}
^!u:: ; ### MAIN ###
WinActivate, ahk_class ThumbnailDeviceHelperWnd
Sleep, 333
WinActivate, BlueStacks ahk_class HwndWrapper[Bluestacks.exe;;5b32fde4-2355-48c5-be51-8927697e9914]
Sleep, 500
ClickMainBuilding(5)
Sleep, 1000
ClickTradeDepot()
Sleep, 1000
ExitTradeDepot()
Return
Esc::ExitApp ; Exit script with Escape key
Loop, x
withLoop, % x
– Yane