A better way would be to save in your own custom format (uses less code: if you have two levels then you have two sets of the same code but with different values), but if you insist on saving as code then here's how to do it:
rem Test object to save position so we can recreate it
make object sphere 1,10
position object 1,13,54,21
rem Save the code to create the object in the same position
open to write 1,"code.dba"
write string 1,"make object sphere 1,10"
write string 1,"position object 1,"+str$(object position x(1)+","+str$(object position y(1))+","+str$(object position z(1)
close file 1
Here's the code I used to save source from my particle creator:
fileExtensions$="DarkBASIC Source (*.dba)|*.dba|Text File (*.txt)|*.txt"
Title$="Please choose export file :"
filename$=""
filename$=call dll(1,"savedialog",fileExtensions$,"x",Title$,Get Dir$() )
set cursor 10,500
If File Exist(filename$) Then Delete File filename$
Open To Write 1,filename$
Write string 1,"Rem ***************************************"
Write string 1,"Rem This code generated by DB PARTICLE FACTORY"
Write string 1,""
Write String 1,"rem Generated on: " + get date$()
Write string 1,""
Write string 1,"Rem ***************************************"
Write string 1,"`Set up system"
Write string 1,"sync on : sync rate 100 : hide mouse : color backdrop 0"
Write string 1,"Rem ***************************************"
Write string 1,"rem Make Particle Object"
Write String 1,"make particles 1,0, 50, 20.0"
Write String 1,""
Write String 1,"rem Configure Particles"
Write String 1,"position particles 1, 0, -15, 0"
Write String 1,"color particles 1,"+str$(r)+","+str$(g)+","+str$(b)
Write String 1,"set particle emissions 1,"+str$(emissions)
Write String 1,"set particle speed 1,"+str$(speed#)
Write String 1,"set particle gravity 1,"+str$(gravity#)
Write String 1,"set particle floor 1,"+str$(floor)
Write String 1,"set particle velocity 1,"+str$(velocity#)
Write String 1,"set particle chaos 1,"+str$(chaos)
Write String 1,"set particle life 1,"+str$(life)
Write String 1,""
Write String 1,""
Write String 1,""
Write String 1,"Rem Main Loop"
Write String 1,"Do"
Write String 1," Sync"
Write String 1,"loop"
Write String 1,""
Write String 1,"` ######## GENERATED WITH DB PARTICLE STUDIO ########"
Write String 1,"` ######## BY DAVID TATTERSALL ########"
Rem close the file
Close File 1
Theres no place like 127.0.0.1
There are 10 people in this world, those who understand binary and those who don't
Bus station = where bus stops. Train station = where train stops. Workstation = ?