Multiple Return Values
BlitzPlus Forums/BlitzPlus Programming/Multiple Return Values
| ||
| 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! |
| ||
| 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]
|
| ||
| I don't think that is possible in B+, but I could be mistaken. |
| ||
| 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 |
| ||
| 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? |
| ||
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). |
| ||
| Wonderful thank you very much! |
| ||
| i used banks for multiple return values. just returned a bank with many values in it. |
| ||
| 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. |