Returning values from functions

Blitz3D Forums/Blitz3D Programming/Returning values from functions

PoliteProgrammer(Posted 2006) [#1]
Hi all!
This might seem like a bit of a stupid question, but how do I return REAL values from functions?

This is what i've got:

e.g.

time# = 0.0
Global Ai# = Rnd(-50, 50) / 100
Global Bi# = Rnd(-50, 50) / 100

Print pathX(time)

Function pathX(t#)
xCoord# = Ai * t^2 + Bi * t

Return xCoord#
End Function

This is just an extract of my code - when I print the value of pathX(time), no matter what time I use I only get integer values.
Any help would be greatly appreciated! Thanks!


Danny(Posted 2006) [#2]
Problem is in HOW you declare a function:

Function PathX(t#) -> will return an integer
end function

Function PathX%(t#) -> will return an integer
Function PathX#(t#) -> will return a float (!)
Function PathX$(t#) -> will return a string
Function PathX.enemey(t#) -> will return a type

If your function is for example called: "Function PathX#(t#)" then it will always return a float! Even if you call the function within your code without the # sign, for example, these two will return the SAME result:

return# = PathX(1.2)
return# = PathX#(1.2)

d.


Naughty Alien(Posted 2006) [#3]
how about


time# = 0.0
Global Ai# = Rnd(-50, 50) / 100
Global Bi# = Rnd(-50, 50) / 100

Value#=pathX(time#)
print Value#

Function pathX(t#)
xCoord# = Ai * t^2 + Bi * t

Return xCoord#
End Function


PoliteProgrammer(Posted 2006) [#4]
Thanks Danny, i forgot about the # after the function name!