Guest weirdwes Posted January 8, 2004 Posted January 8, 2004 Here is what I want to do, but keep in mind this doesn't work as is. $count = 1 Inc($count) Dec($count, -8) MsgBox(0,"Counting Fun","Your $Count now equals: " & $count) Func Inc(BYREF $var, $step) IF $step = 0 then $step = 1 Endif $var = $var + $Step EndFunc Func Dec(BYREF $var, $step) IF $step = 0 then $step = 1 Endif $var = $var - $Step EndFunc The second line fails with an error because I am not passing the $step parameter for the function. How can I make this optional and set it to 1, if it's not included?
CyberSlug Posted January 8, 2004 Posted January 8, 2004 (edited) AutoIt does not support optional parameters in user-defined functions..... Workarounds:1) Pass an array as the single argument, and compute based on the number of elements. (Won't help in this particular example.)EDIT: I don't know why I was using Return in my original code post. Fixed below:2) Use two slightly different function names.$x = 3 $y = 3 MsgBox(0,"", Inc1($x)) MsgBox(0,"", Inc($y, 2) Func Inc1(byRef $var) $var = $var + 1) EndFunc Func Inc(byRef $var, $amount) $var = $var - $amount EndFuncP.S. Dec($count, -8), the way you coded it, will add 8. Edited January 9, 2004 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
jpm Posted January 8, 2004 Posted January 8, 2004 The Optional is in David/JP (Myself) dbg-bastard perhaps Jon will have time to integrate it Func functioname ([byRef]$param1, ... [,Optional [byRef] $paramN+1, ... ]) statement1 ... EndFunc
spt Posted January 9, 2004 Posted January 9, 2004 i just recently started learning PHP... ive known AutoIt v2 for a LONG time, and im now starting to understand v3 pretty well..... how do functions work? ~~ Safeguarding The Land ~~
scriptkitty Posted January 9, 2004 Posted January 9, 2004 You will love funtions, they are like little subroutines, and are very needed since we got rid of the V2 Goto command. oldstyle: send,hi if,winexist,mywindow,,goto,sayhi back: end sayhi: send,hi goto,back New style: send("hi") if winexists("mywindow","") then sayhi() exit func sayhi() send("hi") endfunc They get a lot more complex, and can return values, or work as subroutines. Used in conjunction with Do...Until ,For...Next ,While...WEnd , etc, they come in real handy, and can acomplish much more than the predicessor. AutoIt3, the MACGYVER Pocket Knife for computers.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now