[Problem]Guild Allies and Enemies

08/16/2010 10:20 Arcо#1
Well after two days of having a go at this, and one day of asking people for help, I finally decided it was time to ask the community for help.
Well I am trying to load allies from the Guilds.dat file.
They are defined as
Code:
public Dictionary<uint, string> Allies = new Dictionary<uint, string>();
When something is added to the dictionary its like this.
Code:
Allies.Add(GuildID, GuildName);
Now when saving to the guild.dat file, its saved like this.
Code:
            BW.Write((int)Allies.Count);
            foreach (KeyValuePair<uint, string> kvp in Allies)
            {
                BW.Write(kvp.Key);
                BW.Write(kvp.Value);
            }
And when loading, it loads like this.
Code:
            int a = BR.ReadInt32();
            {
                for (int i = 0; i < a; i++)
                    Allies.Add(BR.ReadUInt32(), BR.ReadString());
                
            }
I get an error at Allies.Add(BR.ReadUInt32(), BR.ReadString()); when loading.
Unable to read beyond the end of the stream.
is the error I get.
Any help?
08/16/2010 11:06 Korvacs#2
When using ReadString() I think it looks for a null value to signify the end of the string, so you'll need to make sure you write that in somewhere, or you could specify a string length value in the file and have it read a string which is String_Length long.
08/16/2010 17:14 CptSky#3
Arco, when you will be on MSN, if you want ask me, I will check with you.