Jump to content

Recommended Posts

Posted

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?

 

 

Posted

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."

Posted (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 by Ontosy
Posted (edited)

Autoit3 should handle and isolate parameter in function how other languages commonly do.

Edited by Ontosy
Posted (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 by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...