i am trying to learn how to properly use functions, so i wrote this program,
#include "dist.dba"
sync on
sync rate 30
hide mouse
autocam off
fog on
fog color RGB(128,128,128)
backdrop on
color backdrop rgb(128,128,128)
load image "grass15.bmp",1
make matrix 1,10000,10000,20,20
randomize matrix 1,100
prepare matrix texture 1,1,2,2
make object sphere 1,50
randomize timer()
position object 1,rnd(9000),0,rnd(9000)
make object sphere 2,1
sx#=object position x(1)
sz#=object position z(1)
do
sy#=get ground height(1,sx#,sz#)+50
position object 1,sx#,sy#,sz#
ay#=camera angle y()
if upkey()=1 then move camera 10
if downkey()=1 then move camera -10
if leftkey()=1 then ay#=wrapvalue(ay#-10)
if rightkey()=1 then ay#=wrapvalue(ay#+10)
cy#=get ground height(1,cx#,cz#)
cx#=camera position x()
cz#=camera position z()
position camera cx#,cy#+35,cz#
position object 2,cx#,cy#+35,cz#
yrotate camera ay#
`rem calls the function here!
Distance(2,1)
set cursor 0,0
print Distance#
sync
loop
and this is the dist.dba function Distance,
Function Distance(object1,object2)
Distance#=sqrt((object position x(object1)-object position x(object2))^2+(object position y(object1)-object position y(object2))^2+(object position z(object1)-object position z(object2))^2)
EndFunction Distance#
it all works fine except that when i tell it to print Distance#, it always prints a 0. can someone please help me?