Posts | ||
---|---|---|
C# Visual Studio reading and writing files | Locked | |
Thread Options | ||
Jul 3 2016 Anchor | ||
I'm working on a text based game so that I can start applying and expanding my programming knowledge. Something I have never done before has come up and I'm hoping someone on here can help me out! I've read that reading and writing into external files is the best way to handle a lot of data like the different rooms of the game and the inventory system, and all the dialogue. I'm not really sure how to do that or what kind of files to use. I mean as far as reading and writing to a file, I can look that up pretty easily, but I don't know what to do with what I take from the files. I also don't know how to write the files exactly. I've started one in xml simply because it seems to be an easy choice since I'm using visual studio, but I'm not sure if this is the right choice or not. An example of what I am trying to do is this: Right a file with a Root Element called Rooms. Then each child element will be each individual room of the map. Beneath those would be the description the player receives about the room, as well as a list of items the player could potentially pick up. The root of my question here is how do I use this file to help me track which room the player is in, and what the player has interacted with in the room, etc. I really hope this makes sense and that someone can help me with this! Thank you! |
||
|
Jul 10 2016 Anchor | |
Chill - this is easy stuff Now for the actual reading/writing - use google. You can find plenty of tutorials on this and it's also covered by the C# documentation (which you need to learn how to use anyway). I don't how it works in C# precisely as I haven't worked with that language - but it's probably similiar to Python and JavaScript, where you first create a file object and then set a path to the actual file as a property of said object. Then you have various functions for processing data (like read line, read character, move position to byte X, defining the row delimiter, etc) and you either read, write, edit or append to that file. Last you use a function for closing the file object. You will get the hang of it quickly! JSON syntax example: Also: JSON is a universal file format great for storing data that needs to be accessible to different applications. Edited by: Nightshade |
||
Jul 10 2016 Anchor | ||
Thank you for the help! I did read through the documentation and it helped quite a bit but I still had some more questions. I think I've got enough figured out now to where I can start doing it and kind of learn the details as I go. That's usually the best way to learn anyways! Thanks again! |
||
Jul 22 2016 Anchor | ||
Hi people, I learn a lot about save and load data wathing this video. Maybe it's good for you too. |
||
Aug 3 2016 Anchor | ||
I'll check this out too! Thanks! |
Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.