JohnOne Posted March 15, 2010 Posted March 15, 2010 (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 March 15, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Richard Robertson Posted March 15, 2010 Posted March 15, 2010 There's no problem with reuse, but you can't have parameters. As a workaround, make a second dummy function that calls the first.
Moderators Melba23 Posted March 15, 2010 Moderators Posted March 15, 2010 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 parameterSet 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Fulano Posted March 15, 2010 Posted March 15, 2010 (edited) If you define your function like this:Func someFunc ($param=default) EndFuncThen 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 March 15, 2010 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!
JohnOne Posted March 15, 2010 Author Posted March 15, 2010 (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 March 15, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
JohnOne Posted March 15, 2010 Author Posted March 15, 2010 (edited) However, what little coding common-sense I have has come over all twitchy about a code structure that requires it! hahasame 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 March 15, 2010 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
MHz Posted March 16, 2010 Posted March 16, 2010 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.
JohnOne Posted March 16, 2010 Author Posted March 16, 2010 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.
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