Return Array From Function

BlitzMax Forums/BlitzMax Beginners Area/Return Array From Function

(tu) ENAY(Posted 2005) [#1]
Is it possible to return an entire array within a function C++ style?

Something like this:-


Graphics 640,480

Global arse[3]

arse[0] = 0
arse[1] = 0
arse[2] = 0

Function moo()
	Local moopface[3]
	
	moopface[0] = 2
	moopface[1] = 67
	moopface[2] = 4
	
	Return moopface
End Function

arse = moo()

Repeat
	Cls
	
	DrawText arse[0], 10,10
	DrawText arse[1], 10,25
	DrawText arse[2], 10,40
	
	Flip
	FlushMem
Until KeyDown(KEY_ESCAPE)



Thanks :)


Ryan Moody(Posted 2005) [#2]
I don't own BlitzMax, but I'm pretty sure you can. Like the variable names!

Ryan


BlitzSupport(Posted 2005) [#3]
An example in the spirit of things...

size = 10

Local MyPants [size]

MyPants = GetPants (size)

For a = 0 Until size
	Print MyPants [a]
Next

' The [] after the name denotes the function returns an array...

Function GetPants [] (num)

	Local Pants [num]
	
	For a = 0 Until Len (Pants)
		Pants [a] = a
	Next
	
	Return Pants
	
End Function



(tu) ENAY(Posted 2005) [#4]
PANTASTIC! ;)

Cheers James.