- Home /
Dat File Location
So i found this script on the internet
StreamWriter writer = new StreamWriter("MyFile.dat");
writer.WriteLine("Hello");
writer.WriteLine("World");
I modified it to my script and added the using system.io;
but where does it write to? I have the script running with no errors but i dont 100% know if it works because i can see where it saves to on a persons computer, i wanted to be able to choose the directory but if i cant well, that kind of sucks. Id imagine it being possible to choose but i dont 100% know yet.
READ BELOW AT THE COMMENTS
EDIT I posted an answer on a different post telling them to go to here so this is an example i use this in...
using UnityEngine;
using System.Collections;
using System.IO;
public class CharacterSelection : MonoBehaviour {
public string CharacterName = "No Character Created!";
public string psi;
public string PVPTeam;
public string Level;
public string gold;
public string EXP;
public string LvlUP;
public string angel;
public string demon;
public string button001;
public int SelectCharacters = 1;
public int CreateCharacters = 0;
// Use this for initialization
void Start () {
PlayerController pc = (PlayerController)GetComponent("PlayerController");
CharacterName = pc.Name;
Level = pc.Level.ToString();
PVPTeam = pc.PVPTEAM;
psi = pc.PSI;
gold = pc.Gold.ToString();
EXP = pc.EXP.ToString();
LvlUP = pc.LvlUP.ToString();
angel = pc.isAngel.ToString();
demon = pc.isDemon.ToString();
}
// Update is called once per frame
void Update () {
PlayerController pc = (PlayerController)GetComponent("PlayerController");
if (SelectCharacters == 1)
{
button001 = "Create Character";
}
else
{
button001 = "Cancel";
}
ReadData();
WriteData();
}
void OnGUI()
{
Select();
Create();
if (GUI.Button(new Rect(Screen.width - 200, Screen.height - 50, 150, 25), button001))
{
if (button001 == "Create Character")
{
SelectCharacters = 0;
CreateCharacters = 1;
}
else
{
SelectCharacters = 1;
CreateCharacters = 0;
}
}
}
public void Select()
{
if (SelectCharacters == 1)
{
GUI.Button(new Rect(10, 100, 10, 10), "<");
GUI.Button(new Rect(250, 100, 10, 10), ">");
if (GUI.Button(new Rect(30, 100, 200, 25), CharacterName))
{
}
}
}
public void Create()
{
Login l = (Login)GetComponent("Login");
if (CreateCharacters == 1)
{
GUI.Label(new Rect(10, 10, 200, 25), "Name: ");
CharacterName = GUI.TextField(new Rect(50, 10, 125, 25), CharacterName);
if (GUI.Button(new Rect(10, 40, 200, 25), "Create Character"))
{
StreamWriter writer = new StreamWriter(Application.dataPath + "Users/" + l.username + CharacterName + ".dat");
writer.WriteLine(CharacterName);
SelectCharacters = 1;
CreateCharacters = 0;
}
}
}
public void ReadData()
{
PlayerController pc = (PlayerController)GetComponent("PlayerController");
Login l = (Login)GetComponent("Login");
StreamReader reader = new StreamReader(Application.dataPath + "Users/" + l.username + CharacterName + ".dat");
string strAllFile = reader.ReadToEnd().Replace("\r\n", "\n").Replace("\n\r", "\n");
string[] arrLines = strAllFile.Split(new char[] { '\n' });
CharacterName = arrLines[0];
Level = arrLines[1];
EXP = arrLines[2];
gold = arrLines[3];
LvlUP = arrLines[4];
psi = arrLines[5];
PVPTeam = arrLines[6];
angel = arrLines[7];
demon = arrLines[8];
}
public void WriteData()
{
PlayerController pc = (PlayerController)GetComponent("PlayerController");
Login l = (Login)GetComponent("Login");
StreamWriter writer = new StreamWriter(Application.dataPath + "Users/" + l.username + CharacterName + ".dat");
writer.WriteLine(pc.Name);
writer.WriteLine(pc.Level);
writer.WriteLine(pc.EXP);
writer.WriteLine(pc.Gold);
writer.WriteLine(pc.LvlUP);
writer.WriteLine(pc.PSI);
writer.WriteLine(pc.PVPTEAM);
writer.WriteLine(pc.isAngel);
writer.WriteLine(pc.isDemon);
}
}
By default, it will save to your project folder. Otherwise, it saves to the directory that the executable is run from. You can change that as you wish, but remember that everyone's filesystem is different, and you'll need to do different stuff depending on whether it is being run on Windows or on a $$anonymous$$ac.
Lets say im running windows 7 and i have an installer that installs it to my C:/Program Files/$$anonymous$$y Company/$$anonymous$$y Game/ and i have it auto create a shortcut to launch my game, is it possible to make it where it saves the dat files to C:/Program Files/$$anonymous$$y Company/$$anonymous$$y Game/Users/
Not sure. I'm not all that familiar with the windows filesystem- I'm a Unix man. I can only assume that it's pretty straight-forward, look up on some .net-specific boards for that.
(Also, I can only post comments at the moment because the devs at QATO can't be bothered fixing an honestly pretty terrible bug with the moderation queue, which stops people from posting questions properly. Right now, only users with above 1000 karma, and you, can see this- and if I try to post an answer, it takes me to a blank page and doesn't do anything.)
alright thanks for the help, and i was wondering because moderators have to "accept" my question first which i could understand whyd they would do something like that but the point of doing it isnt really worth it
It's so true. They could stop robots just by putting in Captcha, and then for the few genuine human spammers they should just give us the ability to delete bad posts. As it is, there isn't even an option on the moderation queue to actually remove a question! Which means that all it does is delay things for new users, annoy old users, and not even allow us to use it for its original purpose!
I mean, there's a button for banning people from the moderation queue, but get this, the button doesn't even work if you're not actually an ad$$anonymous$$!