Ontosy Posted Sunday at 01:19 PM Posted Sunday at 01:19 PM 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 Sunday at 01:26 PM Posted Sunday at 01:26 PM 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 Sunday at 01:28 PM Author Posted Sunday at 01:28 PM (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 Sunday at 01:34 PM by Ontosy
pixelsearch Posted Sunday at 01:42 PM Posted Sunday at 01:42 PM (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 Sunday at 01:44 PM by pixelsearch "I think you are searching a bug where there is no bug... don't listen to bad advice."
Ontosy Posted Sunday at 01:44 PM Author Posted Sunday at 01:44 PM (edited) Autoit3 should handle and isolate parameter in function how other languages commonly do. Edited Sunday at 01:46 PM by Ontosy
argumentum Posted Sunday at 02:47 PM Posted Sunday at 02:47 PM (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 Sunday at 02:48 PM by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Ontosy Posted Sunday at 02:53 PM Author Posted Sunday at 02:53 PM 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 Sunday at 02:56 PM Posted Sunday at 02:56 PM (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 Sunday at 02:58 PM by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Ontosy Posted Sunday at 03:01 PM Author Posted Sunday at 03:01 PM I not search a work around but evidence limites.
argumentum Posted Sunday at 03:05 PM Posted Sunday at 03:05 PM @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