Do something like this
set display mode 800,600,32,1
phy start
phy set gravity 0,-1000,0
randomize timer()
autocam off
position camera 0,300,-800
point camera 0,0,0
for obj=2 to 10
make object sphere obj,50
position object obj,rnd(600)-300,50+rnd(600),rnd(600)-300
phy make rigid body dynamic sphere obj
phy set rigid body linear damping obj,1
next obj
make object box 1,1000,10,1000
phy make rigid body static box 1
dim PositionX(100)
dim PositionY(100)
dim PositionZ(100)
dim OldPositionX(100)
dim OldPositionY(100)
dim OldPositionZ(100)
dim Stuck(100)
dim value(100)
Dist#=2
do
set cursor 0,0
for obj=2 to 10
OldPositionX(obj)=PositionX(obj)
OldPositionY(obj)=PositionY(obj)
OldPositionZ(obj)=PositionZ(obj)
PositionX(obj)=object position x(obj)
PositionY(obj)=object position Y(obj)
PositionZ(obj)=object position Z(obj)
print "Dist X "+str$(PositionX(obj)-OldPositionX(obj))
print "Dist Y "+str$(PositionY(obj)-OldPositionY(obj))
print "Dist Z "+str$(PositionZ(obj)-OldPositionZ(obj))
Stuck(obj)=0
if PositionX(obj)-OldPositionX(obj)<Dist# and PositionX(obj)-OldPositionX(obj)>-Dist#
if PositionY(obj)-OldPositionY(obj)<Dist# and PositionY(obj)-OldPositionY(obj)>-Dist#
if PositionZ(obj)-OldPositionZ(obj)<Dist# and PositionZ(obj)-OldPositionZ(obj)>-Dist#
Stuck(obj)=1
endif
endif
endif
if Stuck(obj)=1
inc value(obj)
if value(obj)>100
value(obj)=0
phy set rigid body position obj,rnd(600)-300,50+rnd(600),rnd(600)-300
endif
else
value(obj)=0
endif
print "Value "+str$(value(obj))
next obj
if spacekey() then phy set rigid body position 2,100,100,100
phy update
loop