Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
Okay, I want to store points and wins in a text document with the following format:
<username> <points> <wins>
What I am doing is this:
var id = m.GetInt(0);
foreach (string line in scoreLines) // scoreLines = File.ReadAllLine(<the_file_dir>);
{
string[] p = line.Split(' ');
if (players[id].username == p[0].ToString())
{
players[id].points = int.Parse(p[1]);
players[id].wins = int.Parse(p[2]);
}
}
I need to be able to read and write correctly and when the values are updated.
(If I missed some information please tell me what I need to include so you can help. )
Offline
Well, I had your format for quite a while, then someone ( I really can't remember the name, speak up if you're you! (ambiguity intended)) told me about a revolutionary not new way of storing data
[oppa] BINARY STYLE
They basically suggested using BinaryWriter and BinaryReader to store data in files much more efficiently. HOWEVER, it's not as easy to see where you're making mistakes with your file, so maybe we should start out with a text file.
Your mysterious variable ID has returned to us. Still not sure where that comes from.
I'm not the king of least operating complexity, so I'd probably just go LINQ.
In this case, you should also take into account what "players" has. IIRC, you're deleting the users as they leave (through "left" messages). If this is the case, we want to preserve their legacies... otherwise there's no point to saving.
That said, my experience is to have two separate collections of users, one for the live data (position, crown, coins, effects, etc), the other for saved data such as wins/points.
If you wanted to get all crazy, you could add a (nullable?) reference to your live players for easy access to saved information.
Once this is all figured out, you're ready to work with the files! You probably could import with adding straight to the collection with the file data... with the { } initializing block.
Offline
You could use a serializer and store the stream to a file. Basically, create a custom class for your values and make a dictionary for username and your class. Keep everything in that dictionary and use it to access your values and simply use a serializer to store your data in a file.
Offline
I can read the file, but saving it seems to be my problem. I'll have to work on this after school. So, like I said, Saving the file is a big issue (without producing doubles).
Offline
use IniFile
Jabatheblob1 made a video about saving and loading wins:
https://www.youtube.com/watch?v=koEVGMBhUNE
Offline
I think I had a friend using "IniFile"... I'm sure there's some advantage to having the solution include the file, but I really don't see it. Every time the bot saved values, the IDE complained the file had changed. Plus, I flat out didn't bother to understand the code that came with... but if it saves the file every time a value changes, that's a no-go as well.
Offline
[ Started around 1732463718.092 - Generated in 0.052 seconds, 13 queries executed - Memory usage: 1.44 MiB (Peak: 1.56 MiB) ]