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 

Optional parameters in function everywhere and...

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
Bobo8



Joined: 09 Sep 2008
Posts: 4
Location: Czech rep.

PostPosted: Fri Sep 12, 2008 6:27 pm    Post subject: Optional parameters in function everywhere and... Reply with quote

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 Shocked
Neither did I.
Back to top
View user's profile Send private message
DerRaphael



Joined: 23 Nov 2007
Posts: 679
Location: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

PostPosted: Fri Sep 12, 2008 7:36 pm    Post subject: Reply with quote

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
}

_________________
    Code:
    /* no comment */
Back to top
View user's profile Send private message
BIG_RED_TEXT



Joined: 12 Jan 2008
Posts: 129

PostPosted: Sat Sep 13, 2008 12:28 am    Post subject: Reply with quote

That's kickass, but I don't think it works if you have expressions in the parameters...
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 7698
Location: Germany (but I only speak English)

PostPosted: Sat Sep 13, 2008 11:28 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List 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