Sign in to follow this  
Followers 0
JohnOne

AdlibRegister() ?

8 posts in this topic

#1 ·  Posted (edited)

I never used it before.

Is there any way to use a function that is also used by the main script itself, to also be an adlib ?

If so, is there anyway to workaround adlib not being able to work with a parameter (The one parameter in my function is optional anyway) ?

EDIT: forgot example to explain my gibberish

AdlibRegister("_test", 1000)

For $i = 0 To 10
    _main()
Next

Func _main()
    Sleep(100000)
    _test()
EndFunc   ;==>_main

Func _test($val = 0)
    If $val > 0 Then
        MsgBox($val, "Blah", "Blah")
    Else
        MsgBox($val, "Nothing", "New")
    EndIf
EndFunc   ;==>_test
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



There's no problem with reuse, but you can't have parameters.

As a workaround, make a second dummy function that calls the first.

Share this post


Link to post
Share on other sites

JohnOne,

It is very easy to use, but do choose the timing carefully (see below). :(

Is there any way to use a function that is also used by the main script itself, to also be an adlib?

I have seen cases where an Ablib function was called again before it ended (because it took too long to execute) and that worked until it ran into the recursion limit, so I cannot see why you cannot use a common function. If it were running it would just pause when the Adlib called it. However, what little coding common-sense I have has come over all twitchy about a code structure that requires it! :)

is there anyway to workaround adlib not being able to work with a parameter

Set a Global variable and get the function to read it directly whenever called?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

If you define your function like this:Func someFunc ($param=default) EndFunc

Then it shouldn't have a problem being called w/o parameters.

Code example proved my intuition incorrect :(

Just a thought: a MsgBox will hang your code until you deal with it, using ConsoleWrite, or writing to a log file might be a better idea.

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hmmm the code works, I never thought it would

I just (for some reason had to declare $val outside of the function

AdlibRegister("_test", 1000)

Local $val

For $i = 0 To 10
    _main()
Next

Func _main()
    Sleep(100000)
    _test()
EndFunc   ;==>_main

Func _test($val = 0)
    If $val > 0 Then
        MsgBox($val, "Blah", "Blah")
    Else
        MsgBox($val, "Nothing", "New")
    EndIf
EndFunc   ;==>_test

Cheers for the replys gentlemen, appreciated.

EDIT: well for my purpose it does anyway, only when called from _main() does it write the value of $val, it is completely ignored by adlibregister.

EDIT2: Either that of $val just dosent hold a value, just only being declared locally

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

However, what little coding common-sense I have has come over all twitchy about a code structure that requires it! :)

haha

same here, but I have nothing constructive to do at the minute and I was just browsing through the helpfile functions to fart about with them :(

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I would not rely on that feature as it appears to be more of a bug to me.

This example shows how the Global variable is used in the function with a ByRef kind of behaviour when it seems that it should not IMO. The value of the Global $var is 500. Shown in the function as parameter $val (which should be local) is 500 and the really bad effect is changing the value of $val in the function changes the value of Global $var to 499.

Global $val = 500
MsgBox(0, "Global value", '$val = ' & $val, 3)
AdlibRegister("_test", 4000)
Sleep(5000)
MsgBox(0, "Global value", '$val = ' & $val, 3)

While 1
    Sleep(10)
WEnd

Func _test($val = 0)
    MsgBox(0, "Local value", '$val = ' & $val, 2)
    $val = 499
EndFunc   ;==>_test

It could be a odd feature if the Local $var remained Local but when it can change/destroy the Global $var then it seems to be a bug.

Share this post


Link to post
Share on other sites

I wouldnt use it that way myself, for stability sake.

But I dont know what Im missing here, because Your example acted exactly how I would have expected, given that when called by adlibregister the function seems to ignore its parameters.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0