streamwriter

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 :stuck_out_tongue:

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;
	}
}

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

http://msdn.microsoft.com/en-us/library/6ka1wd3w(v=VS.80).aspx

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 :frowning: ( 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?

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

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 :smile:! 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 guess it is Close()

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 :smile: But yes, that was the issue. Even in C# I don’t use it however.

Thanks for the input though :stuck_out_tongue: