You want the object to travel along the matrix right? Well then try this code:
`turn sync on
sync on
`make matrix and randomize
make matrix 1,10000,10000,100,100
randomize matrix 1,20
`if you are using DBPro then you also need to update the matrix
update matrix 1
make object cube 1,10
`begin loop
do
set camera to object orientation 1
cubey# = get ground height(1, cubex#, cubez#) + 10
`move cube
if upkey()=1 then cubez#=cubez#+1
if downkey()=1 then cubez#=cubez#-1
if rightkey()=1 then cubex#=cubex#+1
if leftkey()=1 then cubex#=cubex#-1
if spacekey()=1 then cubey#=cubey#+1
if shiftkey()=1 then cubey#=cubey#-1
position object 1,cubex#,cubey#,cubez#
position camera cubex#,cubey#+5,cubez#-40
point camera cubex#,cubey#,cubez#
`sync and end loop
sync
loop
function gravity(Pull)
for a = 1 to 500
if object exist(a)
if object position y(a)>0 then move object down a,Pull
endif
next a
endfunction
You need to get the height of the matrix every loop, otherwise it won't know how high it is at the cube's new position. You should also always position the object after finding the new coordinates, otherwise it'll lag the game a tiny bit and everytime the user presses a key, it won't update until the next loop. Also, I'm not sure why you need a gravity function because the 'Get Ground Height' command will pull the object back down as well.
However, the reason your function wasn't working would be because you're never calling it in your program. The function must be at the bottom of the code and you must call it somwhere in the loop by typing "gravity(-10)" - It basically works just like a command.
"Computers are useless they can only give you answers."