Returning multiple values from a function

I know I’m not exactly a newbie, but I’m having a complete brainfart of a day and this is pretty much a newbie question… 

I’m passing a value to a function, but I want it to return three values based on the calculations it does.  I’ve done this before with no problems, but I can’t for the life of me find where I did it.

As an example…

function colour (num) local r = (math.cos(num)+1)/2 local g = (math.cos(num \* 2 + 0.1)+1)/2 local b = (math.cos(num \* 0.5 + 0.11)+1)/2 return (r,g,b) end local foo = os.time() colour(foo) object:setFillColor(r,g,b) -- I want to use the values returned from the function.

Any help at all would be appreciated.

try this:

I know I’m not exactly a newbie, but I’m having a complete brainfart of a day and this is pretty much a newbie question… 

I’m passing a value to a function, but I want it to return three values based on the calculations it does.  I’ve done this before with no problems, but I can’t for the life of me find where I did it.

As an example…

function colour (num) local r = (math.cos(num)+1)/2 local g = (math.cos(num * 2 + 0.1)+1)/2 local b = (math.cos(num * 0.5 + 0.11)+1)/2 return (r,g,b) end local foo = os.time() local redf,greenf,bluef = colour(foo) object:setFillColor(redf,greenf,bluef) – I want to use the values returned from the function.

Any help at all would be appreciated.

Just note:

Lua do not have fixed number of returned values for functions, so you can even do

local function lotsOfNumbers() return 1, nil, {}, function() end end print(lotsOfNumbers())

You just comma separate returned values (parenthesis are not needed)

try this:

I know I’m not exactly a newbie, but I’m having a complete brainfart of a day and this is pretty much a newbie question… 

I’m passing a value to a function, but I want it to return three values based on the calculations it does.  I’ve done this before with no problems, but I can’t for the life of me find where I did it.

As an example…

function colour (num) local r = (math.cos(num)+1)/2 local g = (math.cos(num * 2 + 0.1)+1)/2 local b = (math.cos(num * 0.5 + 0.11)+1)/2 return (r,g,b) end local foo = os.time() local redf,greenf,bluef = colour(foo) object:setFillColor(redf,greenf,bluef) – I want to use the values returned from the function.

Any help at all would be appreciated.

Just note:

Lua do not have fixed number of returned values for functions, so you can even do

local function lotsOfNumbers() return 1, nil, {}, function() end end print(lotsOfNumbers())

You just comma separate returned values (parenthesis are not needed)