 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Bobo8
Joined: 09 Sep 2008 Posts: 4 Location: Czech rep.
|
Posted: Fri Sep 12, 2008 6:27 pm Post subject: Optional parameters in function everywhere and... |
|
|
1) For more complex functions it would be very helpful to have optional parameters in the middle of the parameter list, not only in the end.
2) For calling functions with optional parameters it will be very helpful to have possibility to use blank parameters. This is especially confusing, because the build in AHK functions have this possibility! When I met with this blank parameter error, I thought that it is my error and a few hours I searched on the internet and in another scripts, finally I have found 2 forum topics, where another people ask about it:
http://www.autohotkey.com/forum/topic32489.html
http://www.autohotkey.com/forum/viewtopic.php?t=18517&start=0&postdays=0&postorder=asc&highlight=optional+parameters+function
There enigmatiqk did not understand the answer, that it isn't possible to have blank parameter, because he didn't believe it
Neither did I. |
|
| Back to top |
|
 |
DerRaphael
Joined: 23 Nov 2007 Posts: 679 Location: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )
|
Posted: Fri Sep 12, 2008 7:36 pm Post subject: |
|
|
Try this way:
| Code: | msgbox % function(",8")
x := 10
msgbox % function("%x%,8")
function(Parameter="a=5,b=2,c=5") {
Static DefaultVarsValues := "a=5,b=2,c=5"
Loop,Parse,DefaultVarsValues,`,
If (RegExMatch(A_LoopField,"(?P<Name>[^=]+)=(?P<Value>.+)",Def)) {
TransForm, Value, Deref, %DefValue%
Var%A_Index% := DefName, %DefName% := Value
}
Loop,Parse,Parameter,`,
if ((VarName:=Var%A_Index%)&&(StrLen(A_LoopField)!=0)) {
TransForm, Value, Deref, %A_LoopField%
%VarName% := Value
}
return a+b+c
}
|
_________________
|
|
| Back to top |
|
 |
BIG_RED_TEXT
Joined: 12 Jan 2008 Posts: 129
|
Posted: Sat Sep 13, 2008 12:28 am Post subject: |
|
|
| That's kickass, but I don't think it works if you have expressions in the parameters... |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 7698 Location: Germany (but I only speak English)
|
Posted: Sat Sep 13, 2008 11:28 pm Post subject: |
|
|
you could use transform, deref to parse out expressions, or concatenate the expressions along the way
| Code: |
function("8, " somevalue + 3 ", string")
|
_________________
Unless noted, all code is UNTESTED.
Answers Here: 1.(Loops, Viruses, etc.) 2.Search 3.RTFM 4.Ask for Help.
PMs will be ignored unless you are hiring me. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|