Sync On
Sync Rate 60
autocam off
set window on
set display mode 800,600,32
set window size 1024,768
global cubecount# = 0 `Total Cubes
global camerax#,cameray#,cameraz# `Camera Angles
global arraycount = 0
Dim selected( 100 )
Make Matrix 1,2000,2000,50,50
Point Camera 1000,100,1000
Do
text 0, 0, "inArray = " + str$( inArray )
text 0, 10, "openSlot = " + str$( openSlot )
pick screen mouseX(),mouseY(),100
x#=camera position x()+get pick vector x()
y#=camera position y()+get pick vector y()
z#=camera position z()+get pick vector z()
camerax# = camera angle x()
cameray# = Camera angle Y()
cameraz# = camera angle z()
If Keystate (17) = 1
move camera 1
endif
If Keystate (31) = 1
move camera -1
endif
If Keystate (30) = 1
Yrotate Camera Wrapvalue(cameray#-1)
endif
If Keystate (32) = 1
Yrotate Camera Wrapvalue(cameray#+1)
endif
If Keystate (16) = 1
Xrotate Camera Wrapvalue(camerax#-1)
ENDIF
If Keystate (18) = 1
Xrotate Camera Wrapvalue(camerax#+1)
ENDIF
OLDMB=MB
MB=mouseclick()
`Collision detection and coloring to place cubes
If MB=1
If OLDMB=0
arraycount# = arraycount# +1
Make object box cubecount#+1,3,10,3 : color object cubecount# +1, rgb(255,255,255)
position object cubecount#+1,x#,Get ground height(1,x#,z#),z#
for n=0 to arraycount
If object collision (cubecount# +1 ,n)
color object cubecount# + 1, rgb(255,0,0)
EndIf
Next n
cubecount# = cubecount# +1
Else
EndIf
EndIF
object = pick object( mousex(), mousey(), 1, 10000 )
IF mouseclick() = 0
resetMouse = 0
ENDIF
IF mouseclick() = 2 and object > 0 AND resetMouse = 0
resetMouse = 1
inArray = 0
FOR searchArray = 1 to 100
IF selected( searchArray ) = object
Print "Found Old"
inArray = searchArray
ENDIF
NEXT searchArray
IF inArray > 0
`deselect object
color object object, rgb(255,255,255)
Print "Deselecting"
selected( inArray ) = 0
ENDIF
IF inArray = 0
FOR findOpenSlot = 1 to 100
IF selected( findOpenSlot ) = 0
`IF Array Count(selected( findOpenSlot )) = 0
Print "Found New"
color object object, rgb(255,127,80)
openSlot = findOpenSlot
findOpenSlot = 100
ENDIF
NEXT findOpenSlot
selected( openSlot ) = object
ENDIF
ENDIF
Sync
Loop
That should work
. Don't know why you were using Array Count so I took it out, and you also didn't have any dimensions in the "selected" array, just empty ()
. You also took out my if statement:
IF selected( findOpenSlot ) = 0
which you need to see if there is an object number already in that array slot. selected( openSlot ) = object should work the same inside or outside the for...next loop, I just put it out
. Any more questions, feel free to ask.
EDIT: Oh and I added a resetMouse variable so that you have to release the mouse before it reads if you've clicked it again, or else it would be reading it as constantly selecting and deselecting.