stigma Posted April 15, 2007 Share Posted April 15, 2007 Hey all! Just a short question to the experienced coders: is it possible to define default parameters, so thta if I try to call a function with less than the normal amount of parameters, it reverts to the default value? -Stigma Link to comment Share on other sites More sharing options...
Kourath Posted April 15, 2007 Share Posted April 15, 2007 (edited) Just a short question to the experienced coders: is it possible to define default parameters, so thta if I try to call a function with less than the normal amount of parameters, it reverts to the default value? yeah Optional parameters are defined by assigning a default value to them, which could be a macro. They are always the last in the definition. If a parameter is given a default value, then all parameters after that one must also be given default values http://www.autoitscript.com/autoit3/docs/keywords/Func.htm like so: Func _Func1($P1, $P2 = 0, $P3 = "abc") endfunc oÝ÷ Øźw5¶©j¶¦z׫³Mú?f§wMú?v«y×jémyÛhѩݪê-i·*ºkzÊ^rدz¢'ò¢çQnÍpØij¶¦z׫²Ë«ºÚ"µÍÑ[ÌJJoÝ÷ ÛMú?f§wMú?v«y«¢fÆ¥+¶Ú4jwjºZmÊ®¢Ö(¹Æ§¢÷«×yö®ÛÚç¬o&v)ඩj¶¦z׫²)íçîËb¢w[.r¬jëh×6_Func1(1, 1, "def") now $P2 and $P3 have been overridden to 1 and "def" respectively. Edited April 15, 2007 by Kourath Link to comment Share on other sites More sharing options...
stigma Posted April 16, 2007 Author Share Posted April 16, 2007 Thanks! Il look into thisw when I get home -Stigma Link to comment Share on other sites More sharing options...
Andrew Peacock Posted May 31, 2007 Share Posted May 31, 2007 Hi all, Related question: I've got a function defined like this: func saveOptions($showAlert=0) msgbox(0, "showalert", $showAlert); Used to debug only ; More code here endfunc If I call the function with saveOptions(0) or saveOptions(1), it works OK. The msgbox appears OK. If I call it with saveOptions() , which should default to '0', I get an undefined variable error. What gives? Andy Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 31, 2007 Moderators Share Posted May 31, 2007 Hi all, Related question: I've got a function defined like this: func saveOptions($showAlert=0) msgbox(0, "showalert", $showAlert); Used to debug only ; More code here endfunc If I call the function with saveOptions(0) or saveOptions(1), it works OK. The msgbox appears OK. If I call it with saveOptions() , which should default to '0', I get an undefined variable error. What gives? AndyWorks fine here. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 31, 2007 Share Posted May 31, 2007 Same as SmOke_N, it works for me: saveOptions() Func saveOptions($showAlert = 0) MsgBox(0, "showalert", $showAlert); Used to debug only ; More code here EndFunc ;==>saveOptions You must have a typo... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Andrew Peacock Posted May 31, 2007 Share Posted May 31, 2007 Same as SmOke_N, it works for me: saveOptions() Func saveOptions($showAlert = 0) MsgBox(0, "showalert", $showAlert); Used to debug only ; More code here EndFunc ;==>saveOptionsoÝ÷ Ù.ë-«ÞjÜ©¢é캷¿ªê-xa¢Wh^²×Û¬x4¶-+¡×¢©ÞÁø¥y«¢+ÙÍÙ=ÁÑ¥½¹Ì ¤()Õ¹ÍÙ=ÁÑ¥½¹Ì ÀÌØíÍ¡½Ý±ÉÐôÀ¤(µÍ½à À°ÅÕ½ÐíÍ¡½Ý±ÉÐÅÕ½Ðì°ÀÌØíÍ¡½Ý±ÉФìUÍѼս¹±ä(ì5½É½¡É)¹Õ¹oÝ÷ Ø ÝÊ·ö·«mÜ(®KìÊØ^~éܶ*'Á«z)àq©eyا*+§jV©§¬¾&ºÚ"µÍÕRPÝÙ]Û][ ÌÍÚ[] ][ÝÜØ]SÜ[ÛÉ][ÝÊ That line fails in the way I've described. Wierd. Andy Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 31, 2007 Share Posted May 31, 2007 (edited) Ah, hold on. I tested it using ONLY this code in a new file: And you're right, it works. The way the function was being called in my original app was via: GUICtrlSetOnEvent($input0, "saveOptions")oÝ÷ Ù8Z¶X§yö¢È§¶°k"7ö÷zÇ+·Z'«t ÝËú®¢×¢ÒÉ'èzÓ§÷§µ©Ý趹RzÓ§÷§µ©e«Þ¶¬yû§rبËajØZ½ãN¥ªÚë^®Äáz¥¥ø¥z+'¢Ø(¡Ú'¶¬J{$¶Æ²²z)j¶¦z׫±»¶²Â)emè Þvz-q«¬yê뢻è^â秶¸±ú+èzÓ§÷§µ©Ý趹RzÓ§÷§µªÞÂìyú+fz{b¢x§+Zµ©e²Úâë"Ç¢»a¢Ç¢¶+'¢Ø Þu©Ýq«¬zÇ«®ìß춸¤zº%ì°Gbµ*hëh¢Ê(8iצ¡©Ý¶©j¶¦z×«È Þu«mçîËb¢wºÈ§z®º+jÉh¬Ê¢}ý¶Úò¶¬z+ZºÚ"µÍÚ[ÛYH ÙÝZXÛÛÝ[Ë]LÉÝÂÜ ][ÝÑÝZSÛ][[ÙI][ÝËJBÝÙ^TÙ] ][ÝÞÑTÐßI][ÝË ][Ý×Ô]Z] ][ÝÊBÕRPÜX]J ][ÝÕÝ ][ÝË BÕRTÙ]Û][ ÌÍÑÕRWÑUSÐÓÔÑK ][Ý×Ô]Z] ][ÝÊBÕRPÝÜX]P]Û ][ÝÔURU ][ÝË L ÍKL L BÕRPÝÙ]Û][ LK ][Ý×Ô]Z] ][ÝÊBÕRTÙ]Ý]J BÚ[HBTÛY L BÑ[[ÈÔ]Z] ÌÍÔ[HH ][ÝØXÉ][ÝÊBNÈÙÐÞ ][ÝÑXYÉ][ÝË ][ÝÉÌÍÔ[HH ][ÝÈ [È ÌÍÔ[JBQ^][[ÈÏOIÝ×Ô]Z] Uncomment the MsgBox() in _Quit() and you get the error back for trying to use the parameter. Learn something new every day... Edited May 31, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
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