how to create a file

Previous topic - Next topic

djtoon

im tring to save to a file
but i get no file

how do i create the file ?

here is my code:

   fileX=OPENFILE(1,pathtofile, 1)
         WRITEBYTE 1,maingamescore
       CLOSEFILE 1

backslider

you want to save a score?
You know the INIOPEN command?

Moru

This is how to open a file for writing:

Code (glbasic) Select
LOCAL ok // status value from fileopen
LOCAL filenr // the id number of this file when it's open
LOCAL value% // The byte to write to the file

filenr = GENFILE() // Get a free ID-number
ok = OPENFILE(filenr, "filename.ext", 0) // 0 = Open the file for write
IF ok = TRUE
WRITEBYTE filenr, value% // writes a byte to the file (value can only be 0 - 255)
WRITESTR filenr, "Hello" // Writes a string, not terminated by carriage return or line-break
CLOSEFILE filenr
ENDIF