Function to return multiple values?

BlitzMax Forums/BlitzMax Beginners Area/Function to return multiple values?

Morbius(Posted 2006) [#1]
How do you return multiple values ex. X,Y,Z from a function?

Do you return them as an array?

Thanks!


degac(Posted 2006) [#2]
an array if they are of the same type, or a type that contains different field-value X,Y,Z


Gabriel(Posted 2006) [#3]
Function DoStuff(X:Int Var,Y:Int Var,Z:Int Var)
   X=1
   Y=2
   Z=3
End Function


Adding Var after the variable type passes the variable by reference instead of by value, which means that you're effectively passing a pointer and any changes you make to that variable within that function will be reflected in the original variable.


H&K(Posted 2006) [#4]
Type AType
Field x,y,z
endtype

Function aFunction:AType()

return Temp:Atype
EndFuction
My feeling is that if the (3) things are so related that you are going to be returning them from a Function. Then make them a Type.
And in the case of say Vertex points passing arrays is ok as well. Its down to what you preffer doing often
But there is no single "correct" way to answer your question, there is nothing wrong with the "By refference" way


Morbius(Posted 2006) [#5]
Fantastic. Thanks all!