hey guys, im having trouble getting streamwriter working. Im not 100% sure what it is lol. so far my understanding is that its a unity function but im slowly coming to belive its a plugin of some sort. I cant find any documentation on it with unity
so heres my code also, i may be doing somthing wrong
but i get the error unknown idendifier(StreamWriter).
function Update () {
if(Input.GetKeyDown("R")) {
sw = new StreamWriter(Application.dataPath + "Account.txt");
sw.WriteLine("A line of text");
sw.close;
}
}
appels
November 6, 2010, 11:09pm
2
itâs a .net function and you can read about it on MSDN.
It does work, and its a function that in-game when the key R is pressed writes something to a stream in this case âA line of textâ then closes the stream , The only problem is I donât know what a stream is, maybe like youtube video streaming?
sooooooooooo erm lol does that mean i must install somthing or some sort of plugin to use it? becuase at the moment it isnt working
appels
November 6, 2010, 11:15pm
5
appels
November 6, 2010, 11:19pm
6
i donât know about unityscript but this works in C#. basicly you import the class you need from .net if itâs allowed in unity and use it.
hmm strange, im looking at various other posts and its been done in JS ( http://forum.unity3d.com/threads/64830-Javascript-streamwriter-(Midi-Style-Recording)?highlight=streamwriter ), is there any other way other than playerprefs becuase i dont understand it to write to text files?
Why are you trying to use streaming perhaps thereâs a simpler or at least more immediate alternative?
appels
November 6, 2010, 11:24pm
9
yes, you still need to import the .net :
import System;
import System.IO ;
becuase streamwriter seems to be used alot :S i found it originally in a refrence book thing i brought
Reading and Writing Text Files
Being able to store and retrieve data within files is very handy for many uses, such as saving high scores, or level data,
or for creating your own file format.
To write to a file simply use the following lines of code:
sw = new StreamWriter(Application.dataPath + â\filename.txtâ);
sw.WriteLine(âA line of textâ);
sw.Close();
To read from file, use the following lines of code:
sr = new StreamReader(Application.dataPath + â\filename.txtâ);
line = sr.ReadLine();
sr.Close();
Debug.Log(line);
StreamWriter comes from System.IO which you must import if you want to use it.
you only have basic frameworks âomnipresent in unityscriptâ
ok thanks dreamora ! always a very helpfup person!
Just to mention that: The MSDN is normally extremely helpfull on these things as it mentions the explicit namespace its in in the full name.
Anything thats not UnityEngine, System.Collections and System commonly needs to be imported explicitely
i think that you are using the wrong langage , you have to use c# , not JavaScript
using UnityEngine;
public class yourClaaName : MonoBehaviour {
void Update()
{ âŚ
Hi Malek.
This thread was posted around 3 years ago But yes, that was the issue. Even in C# I donât use it however.
Thanks for the input though