Posted: 3rd Feb 2004 15:39
this little snippet allows you to keep a logfile for your games:

+ Code Snippet
function write_to_log(line_number,text$)

if file exist("LOG.TMP")=1 then delete file "LOG.TMP"

if file exist("LOG.TXT")=1
 copy file "LOG.TXT","LOG.TMP"
 delete file "LOG.TXT"
 open to write 1,"LOG.TXT"
 write string 1,""
 write fileblock 1,"LOG.TMP"
 delete file "LOG.TMP"
else
 open to write 1,"LOG.TXT"
endif

write string 1,"["+str$(line_number)+"]"+GET DATE$()+"|"+text$
close file 1

endfunction


Its useful for big games, helping people who has problems, example:

write_to_log(5,"Setting Display Mode")
write_to_log(20,"Loading 3D objects")

The reason I made this, is because open to write only works if the file DOESNT exist. This makes a temporary file that gets deleted. Have fun!
Posted: 5th Feb 2004 11:49
what happens if the game crashes before you delete the temp file, and haven't closed the current file yet?
Posted: 5th Feb 2004 17:40
Then a temp file will exist, I can modify the code to prevent this.. But when the file isnt closed isnt a real problem. I've had enough errors with this code (opened the file, then a syntax error, so the file was still opened)