examples of arrays as return type.

BlitzMax Forums/BlitzMax Programming/examples of arrays as return type.

JoJo(Posted 2008) [#1]
Trying to get up to speed with Max...

Does anyone have an examples of using arrays as return types?


fredborg(Posted 2008) [#2]
For Local s:String = EachIn SomeStrings()
	Print s
Next

Function SomeStrings:String[]()

	Return ["this","is","a","simple","example"]

EndFunction
The important bit is the function return type declaration, ie: function name:String[] if it's an array of strings.


JoJo(Posted 2008) [#3]
ok. Now tell me why this isnt working
I get a compile error: Compile Error: Expecting function type

Function p:Int[2] (x:Int, y:Int) 
	Local a:Int[2] =[x, y] 
	Return a
End Function

Local int_array:Int[2] 
int_array = p(5, 6) 

Print int_array[0] 



Perturbatio(Posted 2008) [#4]
Function p:Int[](x:Int, y:Int) 
	Local a:Int[] = [x, y] 
	Return a
End Function

Local int_array:Int[2] 
int_array = p(5, 6) 

Print int_array[0] 


The error message isn't as useful as it could be, it should say something about not specifying the number of elements in the array return type


JoJo(Posted 2008) [#5]
Thanks for that.
Yeah the compiler error messages could be more helpful.
Instead of looking at the number of elements, I'm focusing on moving the type to different spots so the compiler would stop complaining.

But anyway, thanks again!


Czar Flavius(Posted 2008) [#6]
I think you will find cryptic error messages is not unique to any programming language, unfortunately.