XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

How to properly get the GamerTag

Last post 23/10/2009 12:33 by Kagadome. 4 replies.
  • 22/10/2009 23:57

    How to properly get the GamerTag

    I was hoping to use the Player.GamerId to find my Player, but no luck for me. I wrote the following, which works, but I am wondering if there is an easier way?


    private
     void GamerJoinedEventHandler(object sender, GamerJoinedEventArgs e) 
        Player player = new Player { GamerId = e.Gamer.Id, GamerTag = e.Gamer.Gamertag}; 
        e.Gamer.Tag = player; 
        ... 
     
     
    public static Player GetPlayerByGamerTag(string gamerTag) 
        Player player = null
        foreach (Gamer gamer in NetworkGamer.SignedInGamers) 
        { 
            if (gamer.Gamertag.ToUpper().CompareTo(gamerTag.ToUpper()) == 0) 
            { 
                player = gamer.Tag as Player; 
                break
            } 
        } 
        return player; 
  • 23/10/2009 0:50 In reply to

    Re: How to properly get the GamerTag

    Assuming you're the only person playing on your 360 you can just use the IsLocal property.
    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 23/10/2009 2:29 In reply to

    Re: How to properly get the GamerTag

    What I am implementing is a 'tell' command. The tell command parses the text and hands it off to the server so that the server can locate the recipient. Kagadome is the server. Macharia is at his house answering forum questions, but signed in and eagerly awaiting for me to buzz him (because he is the client) and praise him for his latest book.

    Tell Macharia, "Update your blog before you write another book!"

    So, Kagadome needs to find Macharia so that Kagadome can send Macharia the message.
  • 23/10/2009 6:26 In reply to

    Re: How to properly get the GamerTag

    When you get player joined messages, you can build a Dictionary<string, Player> where you can look up players by gamer tag. Remember to remove the players again when you get the player left message :-)

    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 23/10/2009 12:33 In reply to

    Re: How to properly get the GamerTag

    Timely advice. Thanks guys!
Page 1 of 1 (5 items) Previous Next