Official Everybody Edits Forums

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.

#1 2015-08-26 02:40:54, last edited by ParadoxInTheVoid (2015-08-26 14:08:18)

ParadoxInTheVoid
Member
From: ̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺
Joined: 2015-02-18
Posts: 341

[Question] What is the best way to score points and wins?

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. //forums.everybodyedits.com/img/smilies/tongue)


signature.png

Offline

#2 2015-08-26 03:00:41

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,853

Re: [Question] What is the best way to score points and wins?

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

#3 2015-08-26 06:02:21

BuzzerBee
Forum Admin
From: Texas, U.S.A.
Joined: 2015-02-15
Posts: 4,575

Re: [Question] What is the best way to score points and wins?

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.


TdQRyz3.png
https://wiki.everybodyedits.com/images/5/5d/135_bee

Offline

#4 2015-08-26 14:09:51

ParadoxInTheVoid
Member
From: ̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺̺
Joined: 2015-02-18
Posts: 341

Re: [Question] What is the best way to score points and wins?

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


signature.png

Offline

#5 2015-08-26 20:52:18

Srna
Member
Joined: 2015-02-26
Posts: 220

Re: [Question] What is the best way to score points and wins?

use IniFile
Jabatheblob1 made a video about saving and loading wins:
https://www.youtube.com/watch?v=koEVGMBhUNE

Offline

#6 2015-08-26 21:46:14

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,853

Re: [Question] What is the best way to score points and wins?

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

hummerz51440621974534899

Board footer

Powered by FluxBB

[ Started around 1732452813.5135 - Generated in 0.049 seconds, 13 queries executed - Memory usage: 1.43 MiB (Peak: 1.55 MiB) ]