AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Functions in AHK?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
[¤GoO¤]
Guest





PostPosted: Tue Feb 22, 2005 7:18 pm    Post subject: Functions in AHK? Reply with quote

Can you create your own functions? Like:
-----------
Myfunction, Parameter1, Parameter2
Msgbox, %Parameter2%

Myfunction:
Parameter2 := 2 * Parameter1
end function
----------
Confused
Back to top
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Tue Feb 22, 2005 7:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dippy46



Joined: 06 Jul 2004
Posts: 171
Location: Manchester, England.

PostPosted: Tue Feb 22, 2005 7:59 pm    Post subject: Functions Reply with quote

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
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Tue Feb 22, 2005 8:03 pm    Post subject: Reply with quote

Err... just a note to Dippy; it's usually considered bad programming practice to begin variables references with an underscore.
Back to top
View user's profile Send private message
Dippy46



Joined: 06 Jul 2004
Posts: 171
Location: Manchester, England.

PostPosted: Tue Feb 22, 2005 8:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dippy46



Joined: 06 Jul 2004
Posts: 171
Location: Manchester, England.

PostPosted: Tue Feb 22, 2005 8:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Tue Feb 22, 2005 9:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group