Ontosy Posted July 13 Posted July 13 I’m seeing unexpected behavior when using AdlibRegister with a function that has a default parameter. Example: Local $a = "Alx" AdlibRegister("KeyboardShow", 1000) Sleep(5000) Func KeyboardShow($a = True) ConsoleWrite("[$a] = " & $a & @CRLF) EndFunc When KeyboardShow is triggered by AdlibRegister, it prints "Alx" — even though no parameter is passed, and the default is True. Why is it picking up the global $a instead of using the default? In most other languages, the function parameter would shadow the global variable, and the default would apply when no argument is passed. But in AutoIt, it seems like the global variable is used instead — is this expected behavior, or a quirk to avoid?
pixelsearch Posted July 13 Posted July 13 Hi. AutoIt help file, topic AdlibRegister You can not register a function using parameters. Does this answer your question ? "I think you are searching a bug where there is no bug... don't listen to bad advice."
Ontosy Posted July 13 Author Posted July 13 (edited) Quote You can not register a function using parameters. I know this but if register not pass parameter function then parameter have to be default True or not declared and not global value. Any other language this do. Autoit3 is border line? Edited July 13 by Ontosy
pixelsearch Posted July 13 Posted July 13 (edited) What about this ? Global $a = "Alx" ; comment out this line to see a different output AdlibRegister("KeyboardShow", 1000) Sleep(5000) Func KeyboardShow() If Not IsDeclared("a") Then $a = True ConsoleWrite("[$a] = " & $a & @CRLF) EndFunc Edited July 13 by pixelsearch "I think you are searching a bug where there is no bug... don't listen to bad advice."
Ontosy Posted July 13 Author Posted July 13 (edited) Autoit3 should handle and isolate parameter in function how other languages commonly do. Edited July 13 by Ontosy
argumentum Posted July 13 Posted July 13 (edited) 1 hour ago, Ontosy said: Autoit3 should ..take a look at this chunk of code, maybe that will work for you ? The part of: If Int(Execute("$iInit")) == 0 Then Edited July 13 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Ontosy Posted July 13 Author Posted July 13 5 minutes ago, argumentum said: ..take a look at this chunk of code, maybe that will work for you ? The part of: If Int(Execute("$iInit")) == 0 Then you not have a $init at parent level.
argumentum Posted July 13 Posted July 13 (edited) 4 minutes ago, Ontosy said: you not have a $init at parent level. Yes, is the 1st parameter that on a regular Function call, is there, but under OnAutoItExitRegister() or Adlib in your case, none of these parameters exist so, that shows how I got creative with it. Edited July 13 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted July 13 Posted July 13 @Ontosy, this is Sparta, I mean, this is AutoIt. If you rather use languages that have those, use those 🤔 IronFine 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
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