Help - Search - Members - Calendar
Full Version: Functions??
AC Tools Everything Macro > AC Tool Macros > Macro Development
Bear
Looking to use Function for First time and being there's No Help for them in the Help File.

Old way:
LoadRGB X,Y
Call ColorMe
ColorMe Procedure
// IF Red > Green & Blue , Set V1,1
// IF Green > Red & Blue , Set V1,2
// IF Blue > Red & Green , Set V1,3
Set Color_M,V1

New Way:
LoadRGB X,Y
Function ColorX
// IF Red > Green & Blue , Set Result,1
// IF Green > Red & Blue , Set Result,2
// IF Blue > Red & Green , Set Result,3
Set Color_M,$ColorX
------------------
Is this the Right usage? Unable to test at the Moment, Recoding my SWG:Ham_bars.inc to work with LOTR:Lotr_Bars (Healing Bot - party of 5).. cool.gif
ScamWatcher
QUOTE(Bear @ Aug 7 2007, 01:55 PM) *
Looking to use Function for First time and being there's No Help for them in the Help File.

Old way:
LoadRGB X,Y
Call ColorMe
ColorMe Procedure
// IF Red > Green & Blue , Set V1,1
// IF Green > Red & Blue , Set V1,2
// IF Blue > Red & Green , Set V1,3
Set Color_M,V1

New Way:
LoadRGB X,Y
Function ColorX
// IF Red > Green & Blue , Set Result,1
// IF Green > Red & Blue , Set Result,2
// IF Blue > Red & Green , Set Result,3
Set Color_M,$ColorX
------------------
Is this the Right usage? Unable to test at the Moment, Recoding my SWG:Ham_bars.inc to work with LOTR:Lotr_Bars (Healing Bot - party of 5).. cool.gif


This is actually what I wanted to do with my AQ BOT. I want it to click next so I dont have to waste clciks. And the guy from youtube said it was due to the color on the screen. Im sure what ur doing here is what I need to do too.
Ahk
CODE
Constants
  Test = 0
End

Function TestMe
  If $test = 0
    TimeStamp Func_TestMe setting result to Hello
    Set Result = Hello
  Else
    TimeStamp Func_TestMe called,, but doing nothing with Result.
    //Do nothing to Result to see what happens
  End
End

TimeStamp $TestMe

SetConst Test = 1
TimeStamp Result directly (outside of Function) holds: $Result
TimeStamp Manually setting Result to Hi
Set Result = Hi
TimeStamp $TestMe
Ipa
It's a trade off between functions & procedures.

Procedures: can pass in params via "USING", but can't be used inline like a function
Functions: Can be used inline as if they were a constant, but the function can't accept parameters

It's personal preference. The ability to make something generic and code a procedure taking parameters always won out for me. I always used a constant (typically $retval) as a return value from any procedure, and used it instead of a function. Was 2 lines of code instead of 1, but better than setting many global variables to be used inside the function since it couldn't accept any params.



So to use your example:

New Way:
LoadRGB X,Y
Function ColorX
// IF Red > Green & Blue , Set Result,1
// IF Green > Red & Blue , Set Result,2
// IF Blue > Red & Green , Set Result,3
Set Color_M,$ColorX


My Way
Procedure DoStuff USING X, Y
LoadRGB $X,$Y
// IF Red > Green & Blue , Set $retval=1
// IF Green > Red & Blue , Set $retval=2
// IF Blue > Red & Green , Set $retval=3
End Proc

Call DoStuff 111, 222
Set Color_M, $retval



This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.