Modify

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#2558 closed Bug (No Bug)

AdLibRegister and function with default parameter

Reported by: karlkar@… 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 Changed 10 years ago by Jpm

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

comment:2 Changed 10 years ago by guinness

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 Changed 10 years ago by Mat

  • Resolution set to No Bug
  • Status changed from new to 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 Changed 10 years ago by guinness

I would request the user discusses with the community before opening a new ticket.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.