Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by CursedScripter · Oct 30, 2011 at 06:06 AM · filelocationread

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);
 
     }
 }
Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Oct 30, 2011 at 05:05 AM 0
Share

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.

avatar image CursedScripter · Oct 30, 2011 at 05:14 AM 0
Share

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/

avatar image syclamoth · Oct 30, 2011 at 05:23 AM 0
Share

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.)

avatar image CursedScripter · Oct 30, 2011 at 05:28 AM 0
Share

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

avatar image syclamoth · Oct 30, 2011 at 05:38 AM 0
Share

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$$!

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Graham-Dunnett · Oct 30, 2011 at 06:46 PM

http://unity3d.com/support/documentation/ScriptReference/Application-dataPath.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to make/write to files, then read immediately? 1 Answer

file read/write in Android devices(phone/tablet...) 1 Answer

Reading - Writing data to - from file? 2 Answers

I cant read the file i wrote, unless i reload it in VS. 1 Answer

Write and read text files with c# 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges