Function within function possible ? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
WalkerOfTheDay
Posts: 484
Joined: 24 Mar 2016, 03:01

Function within function possible ?

29 May 2017, 02:54

Hi is it possible to call one function from another ?
I tried putting in global but that doesn't work.

Function 1:

Code: Select all

RGB_Euclidian_Distance( c1, c2 ) ; find the distance between 2 colors
	{ ; function by [VxE], return value range = [0, 441.67295593006372]
	  ; that just means that any two colors will have a distance less than 442
	  global
	   r1 := c1 >> 16
	   g1 := c1 >> 8 & 255
	   b1 := c1 & 255
	   r2 := c2 >> 16
	   g2 := c2 >> 8 & 255
	   b2 := c2 & 255
	   result := Sqrt( (r1-r2)**2 + (g1-g2)**2 + (b1-b2)**2 )
	   return Sqrt( (r1-r2)**2 + (g1-g2)**2 + (b1-b2)**2 )
	}	

Function 2:

Code: Select all

	
SwitchDatabase(wintitle, fKey, BGR, BGR2, DB1, DB2, SEQ) ; window title, function key, color to match, other valid color, database 1, database 2, sequence
	{
		global
		SetKeyDelay, 500
		WinWait, %wintitle%, , 1
		if errorlevel
		{
			MsGbox, SAP is niet gestart. Start SAP op !
			WinWait, %wintitle%
		}
		else
		{
			Loop
			{
				WinActivate, %wintitle%
				WinMaximize, %wintitle%
				PixelGetColor, SearchColor, 431, 141
				if RGB_Euclidian_Distance( %BGR%, %SearchColor% ) < 4.3 
				; ^ if the difference between BGR and SearchColor is smaller than 4.3, then activate the current database
				{
					WinActivate, %wintitle%
					break
				}

				if RGB_Euclidian_Distance( %BGR2%, %SearchColor% ) < 4.3 	
				{
					MsgBox, 4096, FOUT, Dit is de %DB2% database !
					Sleep, 2000
					Send, %SEQ%
					WinWait, %wintitle%
					WinActivate, %wintitle%
					Sleep, 100
					continue
				}
				else
				{
					Send, {%fKey%}
					Sleep, 2000
					continue
				}
			}
		}
		
	}
Rohwedder
Posts: 3231
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Function within function possible ?  Topic is solved

29 May 2017, 03:12

Hallo,
Just a try!
Exchange:

Code: Select all

if RGB_Euclidian_Distance( %BGR%, %SearchColor% )
by

Code: Select all

if RGB_Euclidian_Distance( BGR, SearchColor )
WalkerOfTheDay
Posts: 484
Joined: 24 Mar 2016, 03:01

Re: Function within function possible ?

29 May 2017, 03:28

Ah yeah, classic mistake. Stupid me :)

Thanks.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], erikals, Google [Bot], k4rkarin, Kellyzkorner_NJ and 36 guests