I noticed that in many functions the programmers added a return value at the end.
Even though I checked this page, it was not possible for me to understand it completely.
https://autohotkey.com/docs/Functions.htm#return
In my cases, it has never worked to use return value.
I always had to work with global variables.
Can I re-write this script so that I don't have to use global variables, but simply retrieve the values with return?
Code: Select all
#SingleInstance, force ; Allow only 1 instance of this script
#include Gdip.ahk ; Include Gdip-library
global centerX, centerY ; center points of found image
Numpad7::
Click_On_Image("C:\Users\USER\Documents\Logitech Gaming Software\AutoHotKey-Scripts\pics\Notepad++\Play.png") ; Move mouse to this image
return
Click_On_Image(image) ; Move mouse to this image - #FUNKTION#
{
ImageSearch, ix, iy, 100, 30, 1200, 800, *100 %image% ; Search for this image in defined pixel range
if ErrorLevel = 0 ; If image has been found:
{
Find_Center_Point(image, ix, iy) ; Retrieve center point (x and y) of this image and set the final mouse position
MouseMove, centerX, centerY, 0 ; Move cursor to center point (x and y) of found image
}
}
Find_Center_Point(image, ix, iy) ; Retrieve center point (x and y) of this image and set the final mouse position - #FUNKTION#
{
pToken := Gdip_StartUp() ; Start gdip instance
pBitmap := Gdip_CreateBitmapFromFile(image) ; Create new bitmap for this image
Gdip_GetImageDimensions(pBitmap, width, height) ; Retrieve its dimensions (width and height)
Gdip_DisposeImage(pBitmap) ; Delete graphics
Gdip_ShutDown(pToken) ; Close gdip instance
halfX := Round(width / 2) ; halfX is the rounded number of width / 2 (e.g. 25 / 2 = 13)
halfY := Round(height / 2) ; halfY is the rounded number of height / 2 (e.g. 10 / 2 = 5)
centerX := ix + halfX ; centerX = top left corner of image + halfX
centerY := iy + halfY ; centerY = top left corner of image + halfY
;return centerX, centerY ; Nothing gets returned - only empty values
}
(I mean to use global variables if local variables could be used as well.)
Thanks for any help!
Cheers!