Multiple Return Values

BlitzPlus Forums/BlitzPlus Programming/Multiple Return Values

Sauer(Posted 2009) [#1]
Hi,

I was wondering if its possible to have multiple return values in a function. I checked the manuals and searched the forums using the search key "multiple return values".

I tried...
Function test()
  Return 1,2,3
End Function

a,b,c=test()

... as you would in Python but Blitz doesn't work like that apparently.

Thanks in advance!


Nate the Great(Posted 2009) [#2]
I dont know about blitz plus

but in bmax I would use arrays

Function test:Int[]()
     Return [1,2,3]
End Function

Local array[3]
array = test()

Print array[0]
Print array[1]
Print array[2]




Sauer(Posted 2009) [#3]
I don't think that is possible in B+, but I could be mistaken.


blackgecko(Posted 2009) [#4]
The only possibility I see is to create a dim field or a global blitzarray in the beginning and to fill it with values inside the function.

EDIT
*Or use Types


Sauer(Posted 2009) [#5]
I wanted to avoid using an array, as I want my functions to be self contained.

To use Types, do you mean pass and return an instance of a type? How do you do that in BlitzPlus, is it like C?


Yasha(Posted 2009) [#6]
Type ReturnValue
   Field a,b,c
End Type

Function Foo.ReturnValue(a,b,c)
   ret.ReturnValue=New ReturnValue
   ret\a=a+1
   ret\b=b+1
   ret\c=c+1
   Return ret
End Function


That's how I would do it (in Blitz3D).


Sauer(Posted 2009) [#7]
Wonderful thank you very much!


Andres(Posted 2009) [#8]
i used banks for multiple return values. just returned a bank with many values in it.


Sauer(Posted 2009) [#9]
Yes I recently discovered that option as well, as I was finding the solution to another problem; passing arrays.

I was fiddling around with Blitz Arrays, as they are undocumented and a bit cryptic in my opinion, when I found that they were not the solution. Banks prove to be very easily passed between scopes and efficient in managing data.