Sign in to follow this  
Followers 0
ender13

Returning Multiple Variables

7 posts in this topic

What is the syntax for returning multiple variables from a function? I know i coudl use an Array, but that seems a little over done for just 3 variables. I tried using

return($var1, $var2, $var3), but the syntax was wrong. I can't seem to find anything in the help files.

Thanks,

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm not an expert but I thought Function returns one value(variable) in general programming. You could use Global variable to set it while in Function though.

Edited by Joon

Share this post


Link to post
Share on other sites

You could always return an array variable that could hold the multiple values


----[ SandyD ]---

Share this post


Link to post
Share on other sites

I'm just wondering..How would expect to use that information returned by Return

if that actually worked ? First of all Return isn't a function, but a keyword, so the

syntax is ofcourse wrong.

If you could show us some code which shows why you need this, maybe we could

help you solve it. If you want it to return something like "var1 var2 var3", then you

could just do it in a simple code like this :

Return $var1 & " " & $var2 & " " & $var3

Share this post


Link to post
Share on other sites

Figured it out.

I ended up combinging the strings into one variable and returned that.

Thanks

Share this post


Link to post
Share on other sites

I'm just wondering..How would expect to use that information returned by Return if that actually worked

Presumably the same way it works in Lua (Example code is Lua):

var1, var2 = lua_function()
print(var1 .. "\n") -- Prints 1
print(var2 .. "\n") -- Prints 2   

function lua_function
    return 1, 2
end

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