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 

[Solved] Blank Optional 1st Parameter in Function?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Rhys



Joined: 17 Apr 2007
Posts: 710
Location: Florida

PostPosted: Thu Jun 05, 2008 3:49 am    Post subject: [Solved] Blank Optional 1st Parameter in Function? Reply with quote

I'm not sure if this is a bug or not, but the following code fails:
Code:
MsgBox,% Add() ;4 (3 + 1)
MsgBox,% Add(2) ;3 (2 + 1)
MsgBox,% Add(,2) ;Error but should be 5 (3 + 2)

Add(x=3, y=1)
{
    return x + y
}
What am I doing wrong? Is it not possible to leave the first parameter of a function blank but provide other parameters?
_________________
[Join IRC!]


Last edited by Rhys on Thu Jun 05, 2008 6:16 am; edited 1 time in total
Back to top
View user's profile Send private message
Ian



Joined: 15 Jul 2007
Posts: 1151
Location: Enterprise, Alabama

PostPosted: Thu Jun 05, 2008 4:08 am    Post subject: Reply with quote

It doesn't want you to omit parameters.
_________________
ScriptPad/~dieom/dieom/izwian2k7/Trikster/God
Back to top
View user's profile Send private message
Rhys



Joined: 17 Apr 2007
Posts: 710
Location: Florida

PostPosted: Thu Jun 05, 2008 5:39 am    Post subject: Reply with quote

But I can omit parameters in the first two lines without issue.
_________________
[Join IRC!]
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6772
Location: Pacific Northwest, US

PostPosted: Thu Jun 05, 2008 5:51 am    Post subject: Reply with quote

I think all of the omitted parameters must be last. I think this is the same reasoning that all optional parameters in the function definition must be last as well. If you could omit parameters that were followed by non-omitted parameters, then this would not be a requirement.

The closest relevant documentation is
chm wrote:
It is not possible to have optional parameters isolated in the middle of the parameter list. In other words, all parameters that lie to the right of the first optional parameter must also be marked optional.


This could probably be explained a bit further, and may actually be elsewhere in the Functions page, but I did not see it on a quick glance.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Rhys



Joined: 17 Apr 2007
Posts: 710
Location: Florida

PostPosted: Thu Jun 05, 2008 6:15 am    Post subject: Reply with quote

That makes sense, thanks!
_________________
[Join IRC!]
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2393

PostPosted: Thu Jun 05, 2008 6:22 am    Post subject: Reply with quote

There are likely alternatives depending on what you'd like to accomplish Smile
Code:
MsgBox,% Add() ;4 (3 + 1)
MsgBox,% Add(2) ;3 (2 + 1)
MsgBox,% Add("",2)
MsgBox,% Add(myvar,2)
b = pickles
MsgBox,% Add(b,8)


Add(x="", y=1)
{
  if x is not number
    X=3
    return x + y
}
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 -> Bug Reports 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