[Help]5165

12/20/2010 05:02 coreymills#1
i cant seem to figure this out i dont know anything about locks yet could someone help me out.

Error:
Quote:
Value cannot be null
Code:
public static void LoadNPCs()// working
        {
            lock (WriteConnection)//error line
            {
                MySqlCommand Cmd = new MySqlCommand("SELECT * FROM `npc`", WriteConnection);

                  MySqlDataReader DR = Cmd.ExecuteReader();
                  while (DR.Read())
                  {
                      Game.NPC Npc = new NewestCOServer.Game.NPC();
                      Npc.EntityID = Convert.ToUInt32(DR["EntityID"]);
                      Npc.Name = Convert.ToString(DR["Name"]);
                      Npc.Type = Convert.ToUInt16(DR["Type"]);
                      Npc.Flags = Convert.ToByte(DR["Flags"]);
                      Npc.Avatar = Convert.ToByte(DR["Avatar"]);
                      Npc.Loc = new Game.Location();
                      Npc.Loc.Map = Convert.ToUInt16(DR["Map"]);
                      Npc.Loc.X = Convert.ToUInt16(DR["X"]);
                      Npc.Loc.Y = Convert.ToUInt16(DR["Y"]);



                      if (Npc.Flags == 21)
                          Npc.Level = (byte)((Npc.Type - 427) / 6 + 20);
                      if (Npc.Flags == 22)
                          Npc.Level = (byte)((Npc.Type - 437) / 6 + 20);
                      if (Npc.Type == 1500)
                          Npc.Level = 125;
                      if (Npc.Type == 1520)
                          Npc.Level = 125;

                      if (Npc.Flags == 21 || Npc.Flags == 22)
                      {
                          Npc.CurHP = 10000;
                          Npc.MaxHP = 10000;
                      }
                      Game.World.H_NPCs.Add(Npc.EntityID, Npc);
                      
                  }
                DR.Close();
            }
        }
this is the write connection:

Code:
public static MySqlConnection WriteConnection;
12/20/2010 05:29 stealarcher#2
prob not connected to mysql.
12/20/2010 07:03 .Beatz#3
On the error line try just using Lock ()

Most sources should be set out in a way where you dont need to WriteConnection each tme.
12/20/2010 10:22 Korvacs#4
WriteConnection must be initialised before you can lock it.