Author Topic: Setting player aliases?  (Read 1996 times)

ProfessionsQuest

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Setting player aliases?
« on: July 05, 2015, 02:19:13 PM »
Hey, so I'm trying to store some data about a player (specifically an ID used in a database, so it's not the same as TNet's ID), so I figured I could add this ID as an alias, like this:

TNManager.player.AddAlias(studentName);
TNManager.player.AddAlias(studentID);
TNManager.SyncPlayerData();


This seems to work if I check the aliases on the player on the local machine

foreach(string a in TNManager.player.aliases)
{
   if(System.Int32.TryParse(a, out studentID))
      Debug.Log ("Found student ID for player "+TNManager.playerName+": "+studentID);
}


But if I try to check the aliases on another player

foreach(string a in TNManager.GetPlayer(TNManager.objectOwnerID).aliases)
{
   if(System.Int32.TryParse(a, out studentID))
      Debug.Log ("Found other player's student ID: "+studentID);
}


It looks like aliases is null. It's getting the objectOwnerID properly and returns a non-null player, but it doesn't have the aliases list. I'm checking this in a void Awake() method. Am I doing something wrong? Or is there another way to store a custom variable to a player?

EDIT: For reference, I'm calling TNManager.player.AddAlias() before the player connects to the server, but I'm also setting TNManager.playerName at the same time and that's updating properly.
« Last Edit: July 05, 2015, 03:28:15 PM by ProfessionsQuest »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting player aliases?
« Reply #1 on: July 06, 2015, 08:51:43 PM »
Set your aliases like this:
  1.         TNManager.BeginSend(Packet.RequestSetAlias).Write(Steamworks.username);
  2.         TNManager.EndSend();
Only the player can set its own aliases. I'll add a TNManager.SetAlias in the next update.