More than 1 Return Value from a Function Script

Hello I have written a Script Function.
This Function computes me a Position for palletising an returns this Position.
But now I would like to get another Value out of this Function script.
Is this possible? And if it is what I have to for it?

In general, functions take in any number of parameters, but return only 1. This single return value could be an array, for example, which you can then parse individual components from, but it still returned only a SINGLE array. (This is basically what’s happening when your script returns a Pose, since a Pose is simply an array of 6 doubles [x,y,z,rx,ry,rz]. If you wanted to return 6 doubles, loading them into an array and returning THAT is the way to do it.)

Without knowing your specific use case, you may find it valuable to declare a number of variables in your installation. These variables are global to polyscope and can be modified in your script. This would allow you to modify as many variables as you want from your script, and simply return nothing.

This would be more in line with using “void” functions and “pass by reference” if you’re interested in doing research on how different languages handle functions.

Hallo
thanks for your answer. I prefer the solution with the individual array. How can I create an individual array in the UR?
Can you give me an exampel?

Hi @franz.mertens ,

You could return a list which has more than one element like the picture below.

Hope this helps.

Hello,
thanks for your answer. I have written a script wich returns a numeric value and an position. But the script doesn´t starts.
I always get an errormessage. My problem is that I can´t create an installation variable with an array that includes a
variable from type “number” and a variable from type “pose”. Is this not possible?
In the pictiure you can see that I would like to save the result of the function in the varable “ret” (line 10). This is an installation
variable wich includes an array of two numbers. I know that this is not right, but I am not able to create an installation variable
array that includes a number and pose field.

Hi,
The problem is you are trying to return an array that contains different types of data and this is not allowed. ‘2 * a’ is a floating point variable and Pos1 is a pose type. Polyscope does not support this concept of an array of mixed types (this would be a structured data type in some other languages).

1 Like