
-----------------------------------
INFERNO2K
Mon Jun 09, 2003 6:04 pm

Im confused on how to output data to a txt file.....
-----------------------------------
I have a game and I want to output the players name and his score next to his name

var stremin :int %a var that is an int is needed to open a file 
var stremout :int %a var that is an int is needed to open a file 

open: stremout, "Highscores.txt", put %this will open a connection to send data


write : name1, " - ", score1
write : name2, " - ", score2
close: stremout 

I tried this but it doesnt work.

Also how would I be able to keep this txt file and everytime I run this program it will add a new line instead of replacing  the existing information?

Thanks

-----------------------------------
Tony
Mon Jun 09, 2003 6:06 pm


-----------------------------------
read tutorial on writing to files.

if you're opening for put/get you use put get, NOT write/read

-----------------------------------
INFERNO2K
Mon Jun 09, 2003 6:10 pm


-----------------------------------
I've tried and all I get is a Cent symbol, C with a dash through it in the text file.

-----------------------------------
INFERNO2K
Mon Jun 09, 2003 6:25 pm


-----------------------------------
Ok I simply used
var streamOut : int
open : streamOut, "Highscores.txt", put
put : streamOut, name1, "  -  ", score1
put : streamOut, name2, "  -  ", score2 

Now Im confused on how I can keep that file and the program uses it to add onto it instead of replacing the original text.

-----------------------------------
PaddyLong
Mon Jun 09, 2003 7:15 pm


-----------------------------------
open it with mod and seek as well

you really should read the help file for open and read the things listed under "see also" because it lists all the parameters (just type open in your editor, put the cursor on it and press f9 or just open the help and search for open)

any way for your purposes I believe this is what you want...

var streamOut : int 
open : streamOut, "Highscores.txt", put, mod, seek 
seek : streamOut, *  %goes to the end of the file...
put : streamOut, name1, "Â  -Â  ", score1 
put : streamOut, name2, "Â  -Â  ", score2 


-----------------------------------
Andy
Mon Jun 09, 2003 7:18 pm


-----------------------------------
close the file at the end
close (file)

-----------------------------------
PaddyLong
Mon Jun 09, 2003 7:37 pm


-----------------------------------
that too :P

-----------------------------------
Homer_simpson
Mon Jun 09, 2003 9:05 pm


-----------------------------------
this code simply reads and prints text.txt
var fileName : string := "text.txt"           % Name of file
var fileNo : int                        % Number of file
var ch : char
open : fileNo, fileName, get

loop
    exit when eof (fileNo)
    get : fileNo, ch
    put ch ..
end loop
