help with Custom Functions Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ShawnT
Posts: 20
Joined: 07 Mar 2017, 15:19

help with Custom Functions

08 Jan 2020, 15:56

I have been struggling all day to try and get this to work So i have a custom function that has the framework of something i use about a dozen times in a code. Depending on the ErrorLevel and times thru the loop i have it do a multitude of things from naming new variables to mouse clicks.

Code: Select all

	^+u:: 

	ThemeColor := "Default"
			
	;;Getting the current width of the greenfolders program ;;
	WinGetPos,,, WidthWin, HeightWin, GreenFolders - 3.9.56

	;; Getting the current location of the mouse to use after the script is done running. ;;
	MouseGetPos, XposOld, YposOld

	;;Finding the Assessment tab in the menu.

	FindColor("\Images\Universal\OrderSetup\Assessment.jpg", 80, (AddEnding := "A"), (mouseclick, , %x%, %y%),  (MouseClick, , (SFPringX+5), (SFPringY+5)))

	FindColor(Path, ShadesVarible, DoThisThing, DoThatThing, AllElseFailsDoThis)
	{
		global
		
		Loop {
			CustomShade := "*"((A_Index*5)+ShadesVarible)
			ProgressBar := ((A_Index*5)+ShadesVarible)
			
			ImageSearch, X, Y, 0, 0, %WidthWin%, %HeightWin%, %CustomShade% %A_ScriptDir%%path%
			
			If (ErrorLevel = 0){
				%DoThisThing%
				Progress, 0 0, Found @ %ProgressBar% color variations, System Processing , Finding Color
				Sleep 1000
				Progress, off
			}
			Else if (ErrorLevel = 1){
				%DoThatThing%
				Progress, 0 0, Processing @ %ProgressBar% Color variations. , System Processing , Finding Color
				Progress, off
			}
			Else if (A_Index = 20){
				%AllElseFailsDoThis%
				Progress, 0 0, Processing @ %ProgressBar% Color variations. , System Processing , Finding Color
				Progress, off
			}
			sleep 500
		}Until (ErrorLevel = 0 or A_Index = 20) 
	}
Thanks in advance for any help.
User avatar
boiler
Posts: 16965
Joined: 21 Dec 2014, 02:44

Re: help with Custom Functions  Topic is solved

08 Jan 2020, 16:43

It looks like you are using the variables DoThisThing, DoThatThing, AllElseFailsDoThis to hold lines of code to be executed, as if the text contained in a variable can just be replaced and the script would run as if that text is there. It doesn't work that way. Variables can contain values to operate on or display, or even contain the labels to blocks of code to be executed, but they can't be used the way you're trying to use them. The following is NOT valid code and will not produce a MsgBox saying "Hello":

Code: Select all

MyFunction("MsgBox, Hello")
return

MyFunction(codeLine)
{
	%codeLine%
}
This is valid code:

Code: Select all

MyFunction("MsgBoxFunc", "Hello")
return

MyFunction(funcName, parameter)
{
	%funcName%(parameter)
}

MsgBoxFunc(text)
{
	MsgBox, %text%
}
ShawnT
Posts: 20
Joined: 07 Mar 2017, 15:19

Re: help with Custom Functions

09 Jan 2020, 16:23

That works! Thank you so much!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, DataLife, Google [Bot], Rohwedder and 161 guests