Hi again,
So I'm trying to put together a system whereby as the player travels between sectors, only objects in the players current sector are loaded to preserve memory etc. The trouble is as I invoke the delete commands for objects not in the player's sector, other random objects seem to be deleted for no reason! Hence the prog crashes out with me telling it to position objects that dont exist! I'm really scratching my head with this one and wondered if maybe another set of eyes will help. The code snippet shown below shows how sectors are detected and planets are created/deleted. I'm happy to upload the whole project if necessary...
_sector_check:
for gl = 0 to 16
if galactic.x => ((gl*10000000000)- 80000000000) and galactic.x < (((gl+1)*10000000000) - 80000000000) then player.secx = gl
if galactic.z => ((gl*10000000000)- 80000000000) and galactic.z < (((gl+1)*10000000000) - 80000000000) then player.secz = gl
next gl
if PLAYER.SECX <> PLAYER.OLDSECX or PLAYER.SECZ <> PLAYER.OLDSECZ
for nx = 1 to 100
if PLAYER.SECX <> STAR(nx).SECX or PLAYER.SECZ <> STAR(nx).SECZ
if STAR(nx).OBJECT <> 0
if object exist (STAR(nx).OBJECT) = 1 then delete object STAR(nx).OBJECT
if light exist (STAR(nx).LIGHT) = 1 then delete object STAR(nx).LIGHT
endif
endif
if STAR(nx).SECX = PLAYER.SECX and STAR(nx).SECZ = PLAYER.SECZ
STAR(n).OBJECT = STAR(nx).OBJECT
gosub _make_stars
//_make_star(nx)
endif
next nx
endif
PLAYER.OLDSECX = PLAYER.SECX
PLAYER.OLDSECZ = PLAYER.SECZ
return
_make_stars:
rem make a white main sequence
if STAR(n).CLASS = "White - Main Sequence"
STAR(n).OBJECT = find free object()
make object sphere STAR(n).OBJECT,STAR(n).SIZE,40,40
texture object STAR(n).OBJECT,star_white_texture
set object STAR(n).OBJECT,1,0,1,1,0,0
set object emissive STAR(n).OBJECT,rgb(255,255,255)
position object STAR(n).OBJECT,STAR(n).X-galactic.x,STAR(n).Y-galactic.y,STAR(n).Z-galactic.z
l = 1
repeat
inc l
STAR(n).LIGHT = l
until light exist(STAR(n).LIGHT) = 0
if STAR(n).LIGHT => 20 then return
make light STAR(n).LIGHT
set point light STAR(n).LIGHT,STAR(n).X-galactic.x,STAR(n).Y-galactic.y,STAR(n).Z-galactic.z
set light range STAR(n).LIGHT,STAR(n).SIZE*10000
endif
return
Thanks in advance!