| View previous topic :: View next topic |
| Author |
Message |
[¤GoO¤] Guest
|
Posted: Tue Feb 22, 2005 7:18 pm Post subject: Functions in AHK? |
|
|
Can you create your own functions? Like:
-----------
Myfunction, Parameter1, Parameter2
Msgbox, %Parameter2%
Myfunction:
Parameter2 := 2 * Parameter1
end function
----------
 |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Tue Feb 22, 2005 7:20 pm Post subject: |
|
|
Something very similar to user-defined functions is currently the highest priority on the planned features list:
| Quote: | | Passing parameters and receiving return values from subroutines |
|
|
| Back to top |
|
 |
Dippy46
Joined: 06 Jul 2004 Posts: 171 Location: Manchester, England.
|
Posted: Tue Feb 22, 2005 7:59 pm Post subject: Functions |
|
|
This is what I use. The parm can be as many as you need, then all functions just use parms appropriate to the function
| Code: |
; solve Sqrt(5^3)
; use the term _parm(n) as a generic term then you can write
; funcs ad infinitum
_parm1 = 5.00 ; num
_parm2 = 3.00 ; exponent
Gosub Expo
_parm1 := _result
Gosub SquareRoot
msgbox %_result%
; your functions
SquareRoot:
_result := _parm1**.5
Return
Expo:
_result := _parm1**_parm2
return
|
Hope that helps _________________ Simple ideas lie within reach, only of complex minds |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Tue Feb 22, 2005 8:03 pm Post subject: |
|
|
| Err... just a note to Dippy; it's usually considered bad programming practice to begin variables references with an underscore. |
|
| Back to top |
|
 |
Dippy46
Joined: 06 Jul 2004 Posts: 171 Location: Manchester, England.
|
Posted: Tue Feb 22, 2005 8:16 pm Post subject: |
|
|
Not if you want to right libraries it aint, and I write lots of dll's _________________ Simple ideas lie within reach, only of complex minds |
|
| Back to top |
|
 |
Dippy46
Joined: 06 Jul 2004 Posts: 171 Location: Manchester, England.
|
Posted: Tue Feb 22, 2005 8:30 pm Post subject: |
|
|
To be a little more explicit, by using the underscores generally avoids naming conflicts especially when use with includes. I think if you research early Ms documentation you'll find that they even resorted to using double underscores to keep it even deeper ie.
__NameOfDeepVariable _________________ Simple ideas lie within reach, only of complex minds |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Tue Feb 22, 2005 9:53 pm Post subject: |
|
|
| Lol, ok, one: I said "usually." I didn't outright object to using them ever, and two: my internal reasoning was that in some contexts it isn't even valid. At the very least, it makes it slightly less readable. |
|
| Back to top |
|
 |
|