brgn
brgn

Reputation: 1213

How to return multiple strings from a script to the rule sequence in booggie 2?

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.

Upvotes: 2

Views: 394

Answers (4)

brgn
brgn

Reputation: 1213

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") 

Upvotes: 2

user1961684
user1961684

Reputation: 108

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") 

Upvotes: 1

Bluuu
Bluuu

Reputation: 481

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"])

Upvotes: 6

avasal
avasal

Reputation: 14854

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

Upvotes: 3

Related Questions