Question

This is an issue specific to the use of python scripts in booggie 2.

I want to return multiple strings to the sequence and store them there in variables.

The script should look like this:

def getConfiguration(config_id):
    """ Signature:  getConfiguration(int): string, string"""

    return "string_1", "string_2"

In the sequence I wanna have this:

(param_1, param_2) = getConfiguration(1)

Please note: The booggie-project does not exist anymore but led to the development of Soley Studio which covers the same functionality.

Was it helpful?

Solution 3

Still, it's not possible to return multiple values but a python list is now converted into a C#-array that works in the sequence.

The python script itself should look like this

def getConfiguration(config_id):
    """ Signature:  getConfiguration(int): array<string>"""

    return ["feature_1", "feature_2"]

In the sequence, you can then use this list as if it was an array:

config_list:array<string>               # initialize array of string
(config_list) = getConfigurationList(1) # assign script output to that array

{first_item = config_list[0]}           # get the first string("feature_1") 
{second_item = config_list[1]}          # get the second string("feature_2") 

OTHER TIPS

Scripts in booggie 2 are restricted to a single return value. But you can return an array which then contains your strings. Sadly Python arrays are different from GrGen arrays so we need to convert them first.

So your example would look like this:

def getConfiguration(config_id):
    """ Signature:  getConfiguration(int): array<string>"""

    #TypeHelper in booggie 2 contains conversion methods from Python to GrGen types
    return TypeHelper.ToSeqArray(["string_1", "string_2"])

return a tuple

return ("string_1", "string_2")

See this example

In [124]: def f():
   .....:     return (1,2)
   .....:

In [125]: a, b = f()

In [126]: a
Out[126]: 1

In [127]: b
Out[127]: 2

For the example above I recommend using the following code to access the entries in the array (in the sequence):

    config_list:array<string>               # initialize array of string
    (config_list) = getConfigurationList(1) # assign script output to that array

    {first_item = config_list[0]}           # get the first string("feature_1") 
    {second_item = config_list[1]}          # get the second string("feature_2") 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top