It should be something obvious here, but I cant just get it. I cant understand why this code crashes. Maybe I really cant find something plain simple or is it a bug?
sync on
sync rate 30
autocam on
color backdrop 0,0
if file exist("D:\Example.txt") then delete file "D:\Example.txt"
open datafile to write 1,"D:\Example.txt"
write datafile integer 1,1
make object cube 1,10
make mesh from object 1,1:delete object 1
make memblock from mesh 1,1:delete mesh 1
WRITE_DATAFILE_MEMBLOCK(1,1):delete memblock 1
close datafile 1
open datafile to read 1,"D:\Example.txt"
null=datafile integer(1)
DATAFILE_MEMBLOCK(1,1)
make mesh from memblock 1,1:delete memblock 1
make object 1,1,0:delete mesh 1
close datafile 1
do
control camera using arrowkeys 0,2,0.5
sync
loop
function WRITE_DATAFILE_MEMBLOCK(datafile as integer, memblock as integer)
size=get memblock size(memblock)
write datafile dword datafile,size
while size>0
write datafile byte datafile,memblock byte(memblock,current)
inc current:dec size
endwhile
endfunction 0
function DATAFILE_MEMBLOCK(datafile as integer, memblock as integer)
size=datafile dword(datafile)
if memblock exist(memblock)=1 then delete memblock memblock
make memblock memblock,size
while size>0
write memblock byte memblock,current,datafile byte(datafile)
inc current:dec size
endwhile
endfunction size
Replace D:\ with your local drive. This code piece should create a cube, convert it to a memblock then save it to a datafile. But when it tries to read that saved memblock back it pops out a strange error. It says
"Not a memblock byte". What does this means?
Thank you,
Olby
ACER Aspire 5920G: Core2Duo 2.2GHZ, 2GB, GeForce 8600M GT 1280MB, DirectX10, DBPro 6.6b