- Home /
Adding new lines to text file in runtime. (javascript)
I want to create a method of recording what is happening in my drum game, like a midi file where every time a certain drum is played the time it has been played is recorded to a text file in real time and then read back. The problem I have is adding a new line without overwriting the entire file. In Response to the answers, I tried,
import System.IO; var sw = new StreamWriter("TestFile.txt");
function Start () { }
function Update () { if (Input.GetButtonDown("keyOne")) { sw.WriteLine(Time.time); }
if (Input.GetButtonDown("keyTwo")) {
sw.Close();
}
}
But nothing was written at all? And Erics answer, how do you use the append option? Sorry about this but i can't seem to find any IO documentation using JS. :'(
Answer by Will 7 · Oct 24, 2010 at 10:25 PM
Found it! Just put
x.WriteLine("?",true);
The boolean is asking if you want to overwrite or append and it's set to false (overwrite) by default.
Answer by Ony · Sep 14, 2010 at 06:39 AM
The first code sample is failing (unknown identifier "sw") because you have sw declared locally in the Start function instead of globally. When the Update function calls on sw it has no idea what it is because it's only been locally declared.
In your second code you declare sw once locally in the Start function and a second time locally in the Update function, so essentially it's two different variables. Try declaring it globally and see if that helps.
You edited your original question so my answer might not make sense anymore to anyone reading it.
Answer by Eric5h5 · Sep 14, 2010 at 07:23 AM
If you want StreamWriter to append instead of overwrite, then use the append option when creating the StreamWriter object.
Your answer
Follow this Question
Related Questions
changing font + size of text 1 Answer
Limit on GUI Components? 0 Answers
Fading a text gui style 3 Answers
Variable won't appear on UI text (JS) 0 Answers