Forum C# Problem with Partial Classes of Server : Game<Player>

Problem with Partial Classes of Server : Game<Player>

Postby mechanicallyseparatedgames » September 4th, 2014, 11:11 pm

I have successfully made partial classes of classes I made myself. However when I made a partial class out of Server : Game<Player>, I got The name 'someName' does not exist in the current context errors for private variables and methods of the class defined in one file, but used in methods of another. Is there something with Game<Player> that doesn't allow it to be split into partial classes? Or have I done something wrong?

For example, this fails:

In Game.cs:

Code: Select all
namespace MyGame
{
   [RoomType("MyRoom")]
   public partial class Server : Game<Player>
   {
      private int myVariable;

      public override void GameStarted()
      {
         Console.WriteLine("GameStarted(" + RoomId + ")");

         InitializeGame();
      }
   }
}


In MySecondGameFile.cs:

Code: Select all
namespace MyGame
{
   public partial class Server : Game<Player>
   {
      private void Initialize()
      {
         myVariable = 0;
      }
   }
}


Both myVariable and Initialize have The name 'someName' does not exist in the current context errors.
mechanicallyseparatedgames
 
Posts: 18
Joined: June 18th, 2014, 6:24 am

Re: Problem with Partial Classes of Server : Game<Player>

Postby archipdev » September 7th, 2014, 10:42 pm

Maybe the name Server is already taken.

I did this :
Game.cs
Code: Select all
[RoomType("FightLobby")]
    public partial class FightLobby : Game<Player>
    {
    }


FightLobby.cs
Code: Select all
namespace MyGame
{
    public partial class FightLobby : Game<Player>
    {
all code
}
}


It works fine
archipdev
 
Posts: 28
Joined: September 6th, 2014, 10:35 am

Re: Problem with Partial Classes of Server : Game<Player>

Postby mechanicallyseparatedgames » September 8th, 2014, 5:44 am

archipdev,

Thank you for taking the time to respond. My problem was that my default namespace had a typo that I corrected in the Game.cs file, but not in my project's properties, so when I created the second file it had a different namespace. So this problem was just "user error".
mechanicallyseparatedgames
 
Posts: 18
Joined: June 18th, 2014, 6:24 am


Return to C#



cron