I've been getting along fine and learning the program, but I have come across one hitch. In my source code for moving an object across the screen with inertia and colliding with another box I decided to make the different parts into functions. The sliding collision code worked fine in a function, but I can't get the movement to work unless I call it keyctrl: and use gosub to call it. While this isn't a real problem, it does kind of clutter the code and I've heard that functions were better/faster to use. So really I was just wondering why this
function keyctrl()
if rightkey()=1
speedr#=speedr#+.003
zrotate object 1,wrapvalue(object angle z(1)-1)
else
speedr#=speedr#-.001
endif
if leftkey()=1
speedl#=speedl#+.003
zrotate object 1,wrapvalue(object angle z(1)+1)
else
speedl#=speedl#-.001
endif
if speedr#=<0.0
speedr#=0.0
endif
if speedl#=<0.0
speedl#=0.0
endif
position object 1,object position x(1)+speedr#-speedl#,0,0
endfunction
only continues to rotate the box, but won't move it along the X axis...
Here's all of the code
sync on:sync rate 50
make object box 1, 2, 2, 2
color object 1, rgb(rnd(100),rnd(100),rnd(100))
make object collision box 1, -1.5, -1.5, -1.5, 1.5, 1.5, 1.5, 0
make object box 2, 4, 4, 4
make object collision box 2, -2, -2, -2, 2, 2, 2, 0
position camera 1, 0, -10
position object 2, 6, 0, 0
do
col()
keyctrl()
sync
loop
REM controls
function keyctrl()
if rightkey()=1
speedr#=speedr#+.003
zrotate object 1,wrapvalue(object angle z(1)-1)
else
speedr#=speedr#-.001
endif
if leftkey()=1
speedl#=speedl#+.003
zrotate object 1,wrapvalue(object angle z(1)+1)
else
speedl#=speedl#-.001
endif
if speedr#=<0.0
speedr#=0.0
endif
if speedl#=<0.0
speedl#=0.0
endif
position object 1,object position x(1)+speedr#-speedl#,0,0
endfunction
REM sliding collision
function col()
oldposx#=object position x(1)
oldposy#=object position y(1)
oldposz#=object position z(1)
posx#=object position x(1)
posz#=object position z(1)
posy#=object position y(1)
position object 1,posx#,posy#,posz#
if object collision(1,2)>0
dec posx#,get object collision x()
dec posy#,get object collision y()
dec posz#,get object collision z()
endif
position object 1,posx#,posy#,posz#
endfunction
Thanks!
Neeeeeeeewom!