
-----------------------------------
ssr
Mon Jan 31, 2005 5:41 pm

how to createfile in Turing?
-----------------------------------
Another question
how do u create .txt file in Turing.
or any other type of file
Like when u trying to do the high score, u need to create a file in order to do that.
Thanks  :!:  :?:  8)

-----------------------------------
Cervantes
Mon Jan 31, 2005 5:57 pm


-----------------------------------
Turing Reference:

% The "Dir" program.
setscreen ("text")

% Get the current directory
put "Current directory: ", Dir.Current

% Change to a new directory
put "We attempt to change to directory 'xyzzy' " ..
Dir.Change ("xyzzy")
if Error.Last = 0 then
    put "and succeed"
else
    put "but we get the following error: ", Error.LastMsg
end if

% Create the directory
put "Now we create the directory 'xyzzy' " ..
Dir.Create ("xyzzy")
if Error.Last = 0 then
    put "and succeed"
else
    put "but we get the following error: ", Error.LastMsg
end if

% Change to the new directory
put "We once again attempt to change to directory 'xyzzy' " ..
Dir.Change ("xyzzy")
if Error.Last = 0 then
    put "and succeed"
else
    put "but we get the following error: ", Error.LastMsg
end if

% Get the current directory
put "New Current directory: ", Dir.Current

% Create a file in the new directory
put "We now create a file in the current directory"
var f : int
open : f, "junk.dat", put
put : f, "This is a test"
close : f
put "File created"

% Change to the parent directory
put "We move to the parent directory " ..
Dir.Change ("..")
if Error.Last = 0 then
    put "and succeed"
else
    put "but we get the following error: ", Error.LastMsg
end if

% Delete the directory (which should failed because there's a file in it).
put "We try  to delete the directory 'xyzzy' " ..
Dir.Delete ("xyzzy")
if Error.Last = 0 then
    put "and succeed"
else
    put "but we get the following error: ", Error.LastMsg
end if

% Get the current directory
put "New Current directory: ", Dir.Current

% Delete the file in the directory
put "We try to delete the file 'xyzzy/junk.dat' " ..
%File.Delete ("xyzzy/junk.dat")
if Error.Last = 0 then
    put "and succeed"
else
    put "but we get the following error: ", Error.LastMsg
end if

% Delete the directory (which should failed because there's a file in it).
put "We once again try to delete the directory 'xyzzy' " ..
%Dir.Delete ("xyzzy")
if Error.Last = 0 then
    put "and succeed"
else
    put "but we get the following error: ", Error.LastMsg
end if


-----------------------------------
1337_brad
Mon Jan 31, 2005 6:28 pm

In simpler terms...
-----------------------------------
This is a bit simpler, but less informative so I don't know if it will help much.

To creat a text file the code is

var stream1 : int

open : stream1, "filename.txt", put

%and then to put something too it
put : stream1, "hi"

close : stream1


To open a file to read from it, it is: 

var stream1: int
var variable : string
open : stream1, "filename.txt", get

%to get the lines
get : stream1, variable


-----------------------------------
person
Mon Jan 31, 2005 6:39 pm


-----------------------------------
there's actually a tutorial on compsci on FileIO

EDIT : acually, there's 2

-----------------------------------
ssr
Mon Jan 31, 2005 7:33 pm


-----------------------------------
Thanks guys, that was REALLY helpful! :D  8)
