avery Posted February 8, 2009 Share Posted February 8, 2009 Hello,I've been at it all day and night having a blast coding in some Autoit while my Girl Friend is pulling a double at work.I am almost certain the answer to my question is my brain is fried from the aforementioned statement and the only solution to my madness is sleep.I am trying to set more then one local var from a function returning values. Example.Func _main() local $ins = "install_location" Local $inf, $level = _inf($ins) EndFunc Func _inf($ins) ... ... Return($inf, $level) EndFuncThe error I get us unbalanced quotes.Do I have to return an Array or something or can I do multiple returns?ADVthanksANCEavery www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted February 8, 2009 Share Posted February 8, 2009 No multiple returns, use array instead .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
stampy Posted February 8, 2009 Share Posted February 8, 2009 You'd only be able to return one variable without an array. (which it's not the best practice to return arrays due to the coping). However maybe more what you need is to use the variables in the function Byref. Func myFunc(ByRef $x,ByRef $y) Then as the variables change in the function they are changed outside the function as well. Link to comment Share on other sites More sharing options...
Richard Robertson Posted February 8, 2009 Share Posted February 8, 2009 Copying large arrays is fine as long as you don't modify the data. From what I've heard, it doesn't copy the data until you modify it. Link to comment Share on other sites More sharing options...
Malkey Posted February 8, 2009 Share Posted February 8, 2009 Hello, I've been at it all day and night having a blast coding in some Autoit while my Girl Friend is pulling a double at work. I am almost certain the answer to my question is my brain is fried from the aforementioned statement and the only solution to my madness is sleep. I am trying to set more then one local var from a function returning values. Example. Func _main() local $ins = "install_location" Local $inf, $level = _inf($ins) EndFunc Func _inf($ins) ... ... Return($inf, $level) EndFunc The error I get us unbalanced quotes. Do I have to return an Array or something or can I do multiple returns? ADVthanksANCE averyHere is an example of stampy's suggestion using ByRef. _main() Func _main() Local $ins = "install_location" Local $inf, $level _inf($level, $inf, $ins) MsgBox(0, "", "$level contains " & $level & @CRLF & "$inf contains " & $inf) EndFunc ;==>_main Func _inf(ByRef $level, ByRef $inf, $ins) $level = $ins & " Level in inf()" $inf = "$inf in inf()" Return EndFunc ;==>_inf Link to comment Share on other sites More sharing options...
avery Posted February 8, 2009 Author Share Posted February 8, 2009 Here is an example of stampy's suggestion using ByRef. _main() Func _main() Local $ins = "install_location" Local $inf, $level _inf($level, $inf, $ins) MsgBox(0, "", "$level contains " & $level & @CRLF & "$inf contains " & $inf) EndFunc ;==>_main Func _inf(ByRef $level, ByRef $inf, $ins) $level = $ins & " Level in inf()" $inf = "$inf in inf()" Return EndFunc ;==>_inf Thank you very much for that example. It works perfect. I have a related question to these variable and do not understand the internals of AutoIt at all. I'd like to post it here and give it a shot, maybe someone else already knows the answer. Global vs. ByRef vs going out of your way to keep variables in the smallest scope possible (local). Is it for Memory purposes and how much of a difference does it make? Thanks, avery www.abox.orgAvery HowellVisit My AutoIt Websitehttp://www.abox.org Link to comment Share on other sites More sharing options...
martin Posted February 8, 2009 Share Posted February 8, 2009 Thank you very much for that example. It works perfect. I have a related question to these variable and do not understand the internals of AutoIt at all. I'd like to post it here and give it a shot, maybe someone else already knows the answer.Global vs. ByRef vs going out of your way to keep variables in the smallest scope possible (local). Is it for Memory purposes and how much of a difference does it make?Thanks,averyGlobal is not related to ByRef. If a variable is Global it will sit in memory all the time somewhere. If it is Local then it will disappear when the function ends. If you use ByRef then the function is using the variable that has been already declared somwhere else. It might actaully be copied to a local variable while the function operates but that is up to the developers to worry about. The reason to use ByRef is only for the reason you have used it; that is so that you can pass a variable to a function and have it modified. Memory considerations don't come into it IMO. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
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