|
How do I write a line (or four) to a text file? I've looked all over the place but everything I can find is either in C# or is too specific. The documentation has next to nil on the subject. What I'm trying to do is to take the output of four separate text boxes that specify the stats for an enemy and write them into a file. Then, I'd like to load the stats for that enemy at a later point. How can I do this? Thanks in advance - Elliot B. EDIT: I'd like the output to look like this:
I won't go into the specifics, but I need the name, strength, health, and whatnot. I'd also like to be able to read that back in. NOTE: This is not a 'write-my-code' problem. I've seen the warm welcome those receive and would not like to be facing the business end of some of my own comments. I just need a way to do it, because I can't find any documentation. Thanks again. EDIT 2: I guess I'd better go ahead and explain what I'm trying to do. Okay. So, I've been playing some paper RPG games, and thought it would be cool if I could create a sort of 'fighting calculator'. So I went ahead and made one. Then I thought: "What if I could make it so the user could create his own monsters instead of me hardcoding each one?" Which looks like:
For each enemy. So I'm working on a way to get the player input for when he hits 'create new monster' and then types in the variables for it. My program would, theoretically, write the variables to a file, and then read them out again if I needed to use (fight) that monster. Does that make sense? That's why I don't know if PlayerPrefs would work for this. Would it?
(comments are locked)
|
|
You can use System.IO.File.WriteAllText(filePath, yourString); ( http://msdn.microsoft.com/en-us/library/system.io.file.writealltext.aspx ) but honestly I'd stay clear of file IO unless you have to Edit - you'll more likely want AppendAllText instead of WriteAllText if you're going to be adding them Specific to your question: System.IO.File.AppendAllText(yourPath, System.String.Format("{0} {1} {2} {3} {4}", enemyName, ea1, ea2, enemyDefense, enemyHealth)); Not really. It might work, but really what I'm trying to do is... well, I'll edit my Question again. Hang on.
Jul 28 '10 at 03:27 PM
e.bonneville
Ah, thanks. Hang on, let me give that a shot. Sorry - one more n00b question: What's the
Jul 28 '10 at 03:38 PM
e.bonneville
it formats the order the passed variables will appear in the string, in this case it would be in the order they appear, if you did {4} {3} {2} {1} {0} it would be reversed. You can also format it like this "Name '{0}', Ea1 '{1}' etc
Jul 28 '10 at 03:50 PM
sovalopivia
You may need to add a trailing newline onto it to make it work (i.e. {0} {1} {2} {3} {4}n ), but that's a minor issue which will be obvious if it happens ;)
Jul 28 '10 at 03:54 PM
Mike 3
Alright. I plopped the code in. Now it's giving me this error:
Jul 28 '10 at 03:56 PM
e.bonneville
(comments are locked)
|
|
I belierve theres JS specific info about this here
(comments are locked)
|

and what is the specific problem with c#?
I don't do C#. I'm a javascriptonian, through and through.
you're limiting yourself :(
Have you done javascript?