examples of arrays as return type.
BlitzMax Forums/BlitzMax Programming/examples of arrays as return type.
| ||
Trying to get up to speed with Max... Does anyone have an examples of using arrays as return types? |
| ||
For Local s:String = EachIn SomeStrings() Print s Next Function SomeStrings:String[]() Return ["this","is","a","simple","example"] EndFunctionThe important bit is the function return type declaration, ie: function name:String[] if it's an array of strings. |
| ||
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] |
| ||
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 |
| ||
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! |
| ||
I think you will find cryptic error messages is not unique to any programming language, unfortunately. |