GLBasic forum

Main forum => GLBasic - en => Topic started by: djtoon on 2010-Sep-02

Title: how to create a file
Post by: djtoon on 2010-Sep-02
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
Title: Re: how to create a file
Post by: backslider on 2010-Sep-02
you want to save a score?
You know the INIOPEN command?
Title: Re: how to create a file
Post by: Moru on 2010-Sep-02
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