How do I use TitleContainer to read a stream of data (.txt)

I’m attempting to write a text file which will serve as a script for character dialogue along with commands, and I heard that TitleContainer and StreamReader can read from those. How or what way can those two classes be used?

TitleContainer.OpenStream(string path) returns a stream to a file path relative to your application install directory (on most platforms). This stream can be passed to StreamReader to allow you to read lines of text from the file.

1 Like

Thanks for the heads up. I later realized that it had nothing to do with MonoGame haha. Sorry for wasting your time in that regard, but at least I got an answer to that question~

I soon discovered the beauty of System.IO.File.ReadLines(), which ended up being a lot more useful in terms of reading specific lines while ignorning others.

Note that System.IO.File.ReadLines() is for Windows only and it’s slow, if working on windows only, I rather use m_Result = System.IO.File.ReadAllLines( pfilePath ); which returns array of strings and use foreach (string m_Line in m_Result ) to dissect it ^ _ ^ y

1 Like

Good to know there are other ways~
But if it really was for windows, how useful would that be since I’m making a Visual Novel type of game with a textfile having 1000+ lines? I try to imagine an array that big.

1000 ReadLines Vs 1 ReadAllLines() DISK READ ^ _ ^ y 1000 with 256 character per line 256KB on memory which is cheap on windows, but more than that with large row and with multiple condition to select from row line I would choose to use a light Database engine.

EDIT : But of course if ReadLines doesn’t cause a bottleneck and suit your needs stay using it : - D

2 Likes