AutoHotkey Community

It is currently May 27th, 2012, 1:13 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: June 5th, 2008, 3:49 am 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
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!]
Image


Last edited by Rhys on June 5th, 2008, 6:16 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2008, 4:08 am 
Offline

Joined: July 15th, 2007, 1:43 am
Posts: 1320
It doesn't want you to omit parameters.

_________________
Religion is false. >_>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2008, 5:39 am 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
But I can omit parameters in the first two lines without issue.

_________________
[Join IRC!]
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2008, 5:51 am 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
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.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2008, 6:15 am 
Offline

Joined: April 17th, 2007, 1:37 pm
Posts: 761
Location: Florida
That makes sense, thanks!

_________________
[Join IRC!]
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 5th, 2008, 6:22 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2545
There are likely alternatives depending on what you'd like to accomplish :)
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
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Amandaville, BrandonHotkey, chaosad, Yahoo [Bot] and 22 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group