#### Discussion

Back to discussions page
Unconfirmed Posts: 7 Apprentice
Hey everybody,

does anybody know if it is possible to return multiple values in a ur script def() function like return[x,y,z]. It only worked for me to return one value.

Thanks,
Dan

# Comments

• Vacuum Beta tester Posts: 601 Expert
Maybe you could return several values by returning them in a list ?
• Founding Pro, Tactile Sensor Beta Testers Posts: 1,261 Handy
you can return a list, the list must be of the same type for all list elements. You can only return numbers, poses and booleans in a list.
• Unconfirmed Posts: 7 Apprentice
Thanks for the answer. So it is not possible to return more than one variable like return [Var_1, Var_2] and do something like in python [Var_1, Var_2] = function. So I have to put var_1 and var_2 in a list like var_3 = [var_1,var_1] and then return it, return var_3. But if var_1 and var_2 is a list this var_3 = [var_1,var_1]  would not work. Right?
• Founding Pro, Tactile Sensor Beta Testers Posts: 1,261 Handy
You can return the list directly but there are limited types that can be in the list.

Here’s an example that would work as the values are of the same type and they are numbers

def describeCircle(radius):
local circumference = 6.28*radius
local area = 3.14*radius*radius
return [circumference,area]
end

This would not work as center is a point, either list or pose, and radius is a number so types are mismatched.

def describeCircle(a,b,c):
local center = findCenter(a,b,c)
local radius = findRadius(a,b,c)
return [center,radius]
end
• Vacuum Beta tester Posts: 601 Expert
Never tried it but maybe it is possible to return different types by returning a list of list

[[point],[value],[...]]
• Unconfirmed Posts: 7 Apprentice
edited August 2020
Thanks Matthew,

I tried it the way you did.

def describeCircle(radius):
local circumference = 6.28*radius
local area = 3.14*radius*radius
return [circumference,area]
end

and then I tried to call/store the new variables and this didn't work.

[circumference, area] = describeCircle(radius)
• Founding Pro, Tactile Sensor Beta Testers Posts: 1,261 Handy
Yeah, it won’t spread them like that. You would have to do this.

local values = describeCircle(radius)
local area = values[1]
local circumference = values[0]

Or I could use them like this

local volume = getVolumeFromAreaAndHeight(values[1], height)
• Founding Pro, Tactile Sensor Beta Testers Posts: 1,261 Handy
bcastets said:
Never tried it but maybe it is possible to return different types by returning a list of list

[[point],[value],[...]]
Unfortunately a list is not a supported list element type, sucks since a pose (modified list) is a supported list element type
Sign In or Register to comment.
Back to discussions page