Forum C# Access GameCode methods from another class ?

Access GameCode methods from another class ?

Postby remuo » March 9th, 2011, 2:37 pm

I want to call the 'GameCode.Broadcast' message method from a custom class i made. How can i do this ?
remuo
 
Posts: 14
Joined: December 29th, 2010, 6:19 pm

Re: Access GameCode methods from another class ?

Postby Henrik » March 9th, 2011, 2:59 pm

You have to send in an instance of your GameCode class as a parameter to that method, and then call Broadcast on that. Like this:

Code: Select all
[RoomType("MyRoomType")]
public class GameCode : Game<Player> {
   public override void UserLeft(Player player) {
      CustomClass.SomeMethod(this, player);
   }
}

public class CustomClass {
   public static void SomeMethod(GameCode room, Player player) {
      //Do some stuff

      //Broadcast
      room.Broadcast("type", "something");
   }
}
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Access GameCode methods from another class ?

Postby remuo » March 9th, 2011, 4:02 pm

I understand now, thank you Henrik.
remuo
 
Posts: 14
Joined: December 29th, 2010, 6:19 pm


Return to C#



cron