Jump to content

Func with optional arguments, but mandatory if entered


Recommended Posts

The best example is MouseClick, where you have MouseClick($Button, [$x, $y, [..........]]) Where if X is set, Y must be set too.

I do know how to make it so that X and Y are optional, but I am not sure how to get Y mandatory if X is set. I did check the help, but didn't see anything there.

Thanks in advance

Link to comment
Share on other sites

  • Developers

No sure I understand the true issue here, but just do a simply with $y and $x in the Func itself and only make $x mandatory?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You know how you can do MouseClick and not specify a position argument? It will just click where ever the mouse is. If you want to specify a position, you have to specify both X and Y. It is optional to specify an X and Y, but if you do, they both have to be.

Link to comment
Share on other sites

Something like this ?

Func Function($x = Default, $y = Default)
    If ($x <> Default AND $y = Default) OR ($x = Default AND $y <> Default) Then
        Return SetError(1, 0, 0)
    ElseIf $x = Default Then
        ConsoleWrite("X and Y not set")
    Else
        ConsoleWrite("X and Y set")
    EndIf
EndFunc

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...