I am attempting to write something where if the player is within the proximity of a box and a key is hit, something will happen. For a real game example, it would be like a player walking up to a treasure chest/box/whatever and opening it by hitting a key. For now it is just primitives though.
Here is an example of what I have done:
sync on
sync rate 40
`Player
make object sphere 10,10
position object 10,220,0,220
`Boxes
For M = 11 to 99
make object cube (M),4
position object M,RND(10000),0,RND(10000)
Next M
`Main Loop
Do
`Position of boxes
For I = 11 to 99
X2# = object position x(I)
Z2# = object position z(I)
Next I
`Attempted Proximity Code
If X# =< X2# + 2 or X# =< X2#- 2 and Z# =< Z2# + 2 or Z# =< Z2# - 2
If returnkey()=1 then text 0,0, "BLAH"
endif
`Player Controls
aY# = Object angle Y(10)
Rem Control input for camera
If Upkey()=1 then Move object 10,10
If downkey()=1 then Move object 10,-10
If Leftkey()=1 then Yrotate object 10,Wrapvalue(aY#-5)
If Rightkey()=1 then Yrotate object 10,Wrapvalue(aY#+5)
Rem get player object position and store in X# and Z#
X# = Object position x(10)
Z# = Object position z(10)
Rem get new camera position and store in cZ# and cX#
cZ# = Newzvalue(Z#,aY#-180,100)
cX# = Newxvalue(X#,aY#-180,100)
Rem position camera
Position Camera cX#,20,cZ#
Rem point the camera at the player object
Point camera X#,10,Z#
Sync
Loop
Basically, it is supposed to print Blah! when you hit the return key and if you are within +2 or -2 of the box's X and Z positions. The proximity code was tested before with one box and it worked fine, but now it doesn't with multiple boxes and I believe it is because I can't store all 99 boxes X and Z positions in X2# and Z2#. Any help is appreciated!