I was just wondering. How come the following code only works if the control and camera functions/subroutines are called using gosub and not as a user functions. The code compiles but the camera wont rotate around the stationary box.
using gosub:
sync on: sync rate 60
hide mouse
make matrix 1,1000,1000,10,10
make object box 1,1,3,1
position object 1,250,1,250
yrotate object 1,180
do
id=1:gosub control
id=1:gosub camera
sync
loop
control:
objmove=0
objturn1=0
objturn2=0
objangY#=object angle y(id)
mousemove=mousemovex()
if upkey()=1
move object id,2.0
objmove=1
endif
if leftkey()=1
yrotate object id,wrapvalue(objangY#-2)
objturn1=1
endif
if rightkey()=1
yrotate object id,wrapvalue(objangY#+2)
objturn1=1
endif
if objmove=1 and objturn1=0
if mousemove<0
yrotate object id,wrapvalue(objangY#-2)
objturn2=1
endif
if mousemove>0
yrotate object id,wrapvalue(objangY#+2)
objturn2=1
endif
endif
if mousemove<0
camangY#=wrapvalue(camangY#-2)
endif
if mousemove>0
camangY#=wrapvalue(camangY#+2)
endif
return
camera:
objX#=object position x(id)
objY#=object position y(id)
objZ#=object position z(id)
objangY#=object angle y(1)
camD=12
camH=3
camX#=newxvalue(objX#,camangY#,camD)
camZ#=newzvalue(objZ#,camangY#,camD)
camY#=objY#+camH
position camera camX#,camY#,camZ#
point camera objX#,objY#+camH,objZ#
return
using user functions:
sync on: sync rate 60
hide mouse
make matrix 1,1000,1000,10,10
make object box 1,1,3,1
position object 1,250,1,250
yrotate object 1,180
do
control(1)
camera(1)
sync
loop
function control(id)
objmove=0
objturn1=0
objturn2=0
objangY#=object angle y(id)
mousemove=mousemovex()
if upkey()=1
move object id,2.0
objmove=1
endif
if leftkey()=1
yrotate object id,wrapvalue(objangY#-2)
objturn1=1
endif
if rightkey()=1
yrotate object id,wrapvalue(objangY#+2)
objturn1=1
endif
if objmove=1 and objturn1=0
if mousemove<0
yrotate object id,wrapvalue(objangY#-2)
objturn2=1
endif
if mousemove>0
yrotate object id,wrapvalue(objangY#+2)
objturn2=1
endif
endif
if mousemove<0
camangY#=wrapvalue(camangY#-2)
endif
if mousemove>0
camangY#=wrapvalue(camangY#+2)
endif
endfunction
function camera(id)
objX#=object position x(id)
objY#=object position y(id)
objZ#=object position z(id)
objangY#=object angle y(1)
camD=12
camH=3
camX#=newxvalue(objX#,camangY#,camD)
camZ#=newzvalue(objZ#,camangY#,camD)
camY#=objY#+camH
position camera camX#,camY#,camZ#
point camera objX#,objY#+camH,objZ#
endfunction
I'm just curious to know why it doesn't work because i though gosub subroutines were the same as user defined functions.
Thanks