Ontosy Posted 10 hours ago Posted 10 hours ago 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 10 hours ago Posted 10 hours ago 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 10 hours ago Author Posted 10 hours ago (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 10 hours ago by Ontosy
pixelsearch Posted 10 hours ago Posted 10 hours ago (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 10 hours ago by pixelsearch "I think you are searching a bug where there is no bug... don't listen to bad advice."
Ontosy Posted 10 hours ago Author Posted 10 hours ago (edited) Autoit3 should handle and isolate parameter in function how other languages commonly do. Edited 10 hours ago by Ontosy
argumentum Posted 9 hours ago Posted 9 hours ago (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 9 hours ago by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Ontosy Posted 8 hours ago Author Posted 8 hours ago 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 8 hours ago Posted 8 hours ago (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 8 hours ago by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted 8 hours ago Posted 8 hours ago @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