#2558 closed Bug (No Bug)
AdLibRegister and function with default parameter
| Reported by: | Owned by: | ||
|---|---|---|---|
| Milestone: | Component: | AutoIt | |
| Version: | 3.3.9.24 | Severity: | None |
| Keywords: | AdLibRegister function parameter default | Cc: |
Description
Hello.
I've noticed strange thing. After executing the script below on v3.3.8.1 and also v3.3.9.24 I get error:
>Running:(3.3.9.24):D:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Users\Karex\Desktop\test.au3" --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop "C:\Users\Karex\Desktop\test.au3" (10) : ==> Variable used without being declared.: If $var == "0" Then If ^ ERROR ->22:37:13 AutoIt3.exe ended.rc:1 >Exit code: 1 Time: 1.656
The code is:
AdlibRegister("go")
While 1
Sleep(10000)
WEnd
Exit
Func go($var = "1")
If $var == "0" Then
Exit
EndIf
EndFunc
Looks like AdLibRegister calls go function in such a way that $var is not declared. It can be walked around by using isDeclared, however it is not the correct behaviour.
Attachments (0)
Change History (4)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Also your example is kind of pointless in that the default parameter is set to 1 so it will never exit the script just by polling the function every 250ms.
comment:3 by , 12 years ago
| Resolution: | → No Bug |
|---|---|
| Status: | new → closed |
This is standard behaviour for all the AutoIt functions that behave like this. As mentioned, the workaround is to use IsDeclared, however the correct solution is to create a new wrapping function that does not have any parameters.
This behaviour is documented under AdlibRegister:
You can not register a function using parameters.
Likewise in HotkeySet:
The called function can not be given parameters. They will be ignored.
So as far as I'm concerned this is not a bug.
As to whether it should fill default variables, that could be a feature request. The only issue I see with that is you could have a function where half the variables are defined, because they have default values, and the other half aren't, which is confusing.
Feel free to re-open as a feature request if you still think it is important, or PM me on the forums if you would like to debate it further.
comment:4 by , 12 years ago
I would request the user discusses with the community before opening a new ticket.

The register func does not support any parameter.
So for me the script must use Global variable if needed.