trying to return something from a function

BlitzMax Forums/BlitzMax Beginners Area/trying to return something from a function

DREAM(Posted 2008) [#1]
	Function InsideQuad(px:Float, py:Float, x0:Float, y0:Float, x1:Float, y1:Float, x2:Float, y2:Float, x3:Float, y3:Float) 
		If dot(x0, y0, x1, y1, px, py) > 0
			If dot(x1,y1,x2,y2,px,py)>0 
				If dot(x2,y2,x3,y3,px,py)>0 
					If dot(x3,y3,x0,y0,px,py)>0 
						Return True
					EndIf 
				EndIf 
			EndIf 
		EndIf 
	End Function


keeps coming up with an error

compile error: Function can not return a value

what am i doing wrong here?


LarsG(Posted 2008) [#2]
mauybe change the first line to this?
	Function InsideQuad:int(px:Float, py:Float, x0:Float, y0:Float, x1:Float, y1:Float, x2:Float, y2:Float, x3:Float, y3:Float) 


Haven't tried it, but worth a shot..


johnnyfreak(Posted 2008) [#3]
you return true only if *all* ifs are true.
but, if one is false? you return nothing.

try adding "return false" when if's guard is false


DREAM(Posted 2008) [#4]
thats it...thanks.....I have it on superstrict else it probably would of worked......phew...


Brucey(Posted 2008) [#5]
try adding...


Nope :-)

The error is because the function hasn't been defined with a return Type, as Lars notes above.

As far as the returning nothing idea goes, if you don't implicitly return something, the default for that return Type is returned. So, for an Int you would get zero returned. For an Object, you would get Null returned.


HTH


johnnyfreak(Posted 2008) [#6]
i'm learning bmax recently. ;)
So if i define a function with a return type and not write any "return", it returns the default value?

interesting...

And if i don't define any return type, is it similar to the void function of java or C/C++?


CS_TBL(Posted 2008) [#7]
Dunno, I'm on superstrict here, so whenever I omit details like those, BMax kicks my ass. I estimate that outside any strictness Bmax may be assuming an int as return type. Anyway, superstrict ftw!