The first thing you need to consider when making save files is what format you want to save all of your objects as. I suggest making a nice, readable text file format which could look like this:
OBJECT 1
CUBE
SIZE 10 10 10
POSITION 0 0 10
ROTATE 90 45 45
COLOR 255 0 0
GHOST 0
OBJECT 2
SPHERE
SIZE 10 5 10
POSITION 0 0 0
ROTATE 0 0 0
COLOR 0 255 0
GHOST 1
So how would we do that? Writing it is quite simple really:
function OutputObjects( StartID , EndID , Name$ )
rem local variables
local n as integer
rem open a file for writing
FileID = find free file()
open to write FileID , Name$
rem loop through all objects
for n = StartID to EndID
rem make sure object actually exists
if n > 0
if object exist( n )
rem output data
write string FileID , "OBJECT " + str$(n)
if GetObjectType( n ) = sphere then write string FileID , "SPHERE"
if GetObjectType( n ) = cube then write string FileID , "CUBE"
if GetObjectType( n ) = cylinder then write string FileID , "CYLINDER"
write string FileID , "SIZE " + str$(object size x( n )) + "," + str$(object size y( n )) + "," + str$(object size z( n ))
write string FileID , "POSITION " + str$(object position x( n )) + "," + str$(object position y( n )) + "," + str$(object position z( n ))
rem etc.
endif
endif
next n
close file FileID
endfunction
Loading it is just as simple:
function LoadObjects( Name$ )
rem local variables
local FileID as integer
local currentObject as dword
local uString$ as string
rem open file
FileID = find free file()
open to read FileID , Name$
rem load all objects
repeat
rem read next string
read string FileID , uString$
rem set new object index
if left$(uString$,6) = "OBJECT" then currentObject = val( right$(uString$,len(uString$)-7))
rem make an object
if uString$ = "CUBE" then make object cube currentObject , 1
if uString$ = "SPHERE" then make object sphere currentObject , 1
if uString$ = "CYLINDER" then make object cylinder currentObject , 1
rem size
if left$(uString$,4) = "SIZE"
split string uString&
scale object currentObject , val(get split word$(1))*100 , val(get split word$(2))*100 , val(get split word$(3))*100
endif
rem etc.
until file end(FileID)
rem close file
close file FileID
endfunction
You'll have to complete the code, but you get the idea.
TheComet
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown