Hi all,
Sorry for asking what may be obvious, I’m just not used to pass by reference type languages.
In one of my functions I do a lot of work that lead to three variables being updated at the end. From my MATLAB background, I am basically wired to define a multi-output function. But this seems not to be supported in GPScript (there is only a single result in all the examples I’ve found).
An alternative is of course to write the same function three times with different names and return only one of the variables each time. But this does three times the work at run-time and is not advisable for a myriad of reasons.
Do I understand correctly that one way to do this is as in the following function that explicitly returns a string but also updates one of its input arguments?
Function doSomething(a : Integer, b : Integer Array) returns String
var ExampleStrings : String Array
ExampleIntegers : Integer Array
ExampleStrings = ["a","b", "c", "d", "e", "f"]
ExampleIntegers = [10, 20, 30, 40, 50, 60]
result = ExampleStrings[a] // First output
b[a] = ExampleIntegers[a] // Second output is an updated version of b
End
The function is called in a context such as this
var myString : String
x : Integer Array
x = [10, 3, 5, 2, 7, 9]
myString = doSomething(3, x)
which would set myString = “c” and x = [10 , 3, 30, 2, 7, 9]
The integer array x that is passed to the function as argument b is not an input to the function (as I would read it with my background) but an output. It has no purpose as an input (although it could) but it is passed to the function only for the purpose of being updated.
Is this a correct way of viewing how GPScript handles arguments in user-functions?