Jump to content

Return a vector from a getter


photo

Recommended Posts

Hi,

I'm not really familiar with the UnigineScript API, I wanted to know if there is a way to use a getter to return a vector, but syntaxes like :

int[] getArray();

seem wrong. Do you know how I can do it ?

Thanks !

Link to comment
On 8/25/2017 at 9:13 PM, p.roman said:

Hi,

I'm not really familiar with the UnigineScript API, I wanted to know if there is a way to use a getter to return a vector, but syntaxes like :


int[] getArray();

seem wrong. Do you know how I can do it ?

Thanks !

Hi!
Unfortunately, you can't return use container as a function return type via UnigineScript directly.

Quote

https://developer.unigine.com/en/docs/2.5/code/uniginescript/language/functions?rlang=cpp#returning

Return Values

Values are returned with the help of an optional return statement. Any data type may be returned, except for vector, map, and enum.

As a solution, you can pass a container as a function parameter. You can read about passing containers as arguments in the documentation: https://developer.unigine.com/en/docs/2.5/code/uniginescript/language/functions?rlang=cpp#passing.

Quote

Passing Containers as Arguments

To pass a vector or a map as an argument, use a proper function declaration, as shown below:

Source code (UnigineScript)
void foo(int a[]) {
	a[13] = 321;
}

int arr[] = ( 1, 2, 3, 4 );
foo(arr);

 

Link to comment
×
×
  • Create New...