Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: xandeck on May 05, 2016, 08:56:52 AM

Title: TNet 3 - Send DataNode to ChannelData
Post by: xandeck on May 05, 2016, 08:56:52 AM
Hello Aren,

I am trying to get a DataNote through SetChannelData... is it not possible?

This works good:
  1. TNManager.SetChannelData("_name", "my name");
  2. TNManager.SetChannelData("_maxPlayers", 3);
  3.  
  4. string name = TNManager.GetChannelData<string>("_name");
  5. int number = TNManager.GetChannelData<int>("_maxPlayers");
  6.  

But this dont work:

  1. DataNode node = new DataNode();
  2. node.SetChild("_name", "my name");
  3. node.SetChild("_maxPlayers", 3);
  4. TNManager.SetChannelData("_node", node);
  5.  
  6. void GetDataTest()
  7. {
  8.         DataNode node = TNManager.GetChannelData<DataNode>("_node");
  9.         string name = "";
  10.         int number = -1;
  11.         name = tempNode.GetChild<string>("_name", name);
  12.         number = tempNode.GetChild<int>("_maxPlayers", number);
  13. }
  14.  
Title: Re: TNet 3 - Send DataNode to ChannelData
Post by: ArenMook on May 05, 2016, 05:02:48 PM
Use
  1. TNManager.GetChannel(id).dataNode
Title: Re: TNet 3 - Send DataNode to ChannelData
Post by: xandeck on May 05, 2016, 08:45:47 PM
It did not work, I must be doing something wrong.

This is what I am doing to send:
  1. // ################################################################################################
  2.         /// <summary>
  3.         /// Sends channel update
  4.         /// </summary>
  5.         void _Room_UpdateChannel_SendToAll ()
  6.         {
  7.                 DataNode node = new DataNode();
  8.                 node.SetChild("_name", _roomChoosenData._name);
  9.                 node.SetChild("_mapChoosen", _roomChoosenData._mapChoosen);
  10.                 TNManager.SetChannelData("_node", node);
  11.         }
  12.  

And to receive:

  1. // ################################################################################################
  2.         /// <summary>
  3.         /// Called when channel data change
  4.         /// </summary>
  5.         void _CallOnChannelDataChange(Channel ch, string path, DataNode dataNode)
  6.         {
  7.                 _roomChoosenData = new _RoomData();
  8.                 _roomChoosenData._channelId = ch.id;
  9.  
  10.                 DataNode tempNode = TNManager.GetChannel(TNManager.lastChannelID).dataNode;
  11.                 _roomChoosenData._name = tempNode.GetChild<string>("_name", _roomChoosenData._name);
  12.                 _roomChoosenData._mapChoosen = tempNode.GetChild<string>("_mapChoosen", _roomChoosenData._mapChoosen);
  13.         }
  14.  

It just comes as blank, nothing inside those vars (and I know it is not blank).
By the way, its there a better way to get from Channel when its data changes? I tried with the parameter dataNode, no luck.
Thanks
Title: Re: TNet 3 - Send DataNode to ChannelData
Post by: ArenMook on May 05, 2016, 08:57:28 PM
Why do you have underscores in front of everything? It's hella annoying to type... I'm just going to remove them from the code below because I'm tired of underscoring every word. :P
  1. TNManager.SetChannelData("name", roomChosenData.name);
  2. TNManager.SetChannelData("mapChosen", roomChosenData.mapChosen);
  1. void CallOnChannelDataChange (Channel ch, string path, DataNode dataNode)
  2. {
  3.     if (path== "name") Debug.Log("Name: " + dataNode.value + " also available as " + TNManager.GetChannelData<string>("name"));
  4.     else if (path == "mapChosen") Debug.Log("Map: " + dataNode.value + " also available as " + TNManager.GetChannelData<string>("mapType"));
  5. }
Or the easier method, if you prefer... make your "RoomData" serializable by prefixing it with [System.Serializable], then:
  1. TNManager.SetChannelData("roomData", roomChosenData);
  1. void CallOnChannelDataChange (Channel ch, string path, DataNode dataNode)
  2. {
  3.     if (path == "roomData") Debug.Log(dataNode.Get<RoomData>().name + ", " + dataNode.Get<RoomData>().mapChosen);
  4. }
Title: Re: TNet 3 - Send DataNode to ChannelData
Post by: xandeck on May 05, 2016, 09:07:56 PM
That was really nice, thanks. My RoomData is already serializable =)
I did not know TNet could just send classes serialized (it will really make my life easier).
Thank you for this.

About the underscores, I got used to it when working in another company when I was just a programmer (it was easier to see what were my own vars, functions, etc, if I just typed "_" before anything).. lol ...
Title: Re: TNet 3 - Send DataNode to ChannelData
Post by: ArenMook on May 05, 2016, 09:10:07 PM
You should have ragequit that company the minute they told you to use underscores in front of everything. Flipped the desk and left. Nothing else to do with an abomination like that.
Title: Re: TNet 3 - Send DataNode to ChannelData
Post by: xandeck on May 05, 2016, 09:21:55 PM
I got used to it, lol, now I kinda like it (it is good with Monodevelop)

About the channel, it works, thanks.
Title: Re: TNet 3 - Send DataNode to ChannelData
Post by: Bradamante3D on May 06, 2016, 03:37:15 PM
You should have ragequit that company the minute they told you to use underscores in front of everything. Flipped the desk and left. Nothing else to do with an abomination like that.

It's not that simple. There are languages - or rather: language communities - where the underscore is an accepted denotation. Python for example does not have private variables and instead replaces this language feature with a community agreement of putting an underscore in front of private variables. In your Unity code you usually use

  1. mPrivateVar

in other places I've seen

  1. m_PrivateVar

and in Python it would be

  1. _privateVar

and I kinda  like it.

Also note there are cultural factors to consider. On the german QUERTZ keyboard for example the underscore is very easy to produce, just as easy as an "m".

P.S. Yeah I know this isn't exactly TNet-related. Don't worry ... I will shower you with questions on how to combine TNet with Entitas very soon :P
Title: Re: TNet 3 - Send DataNode to ChannelData
Post by: ArenMook on May 07, 2016, 11:13:28 PM
The key is "private member" here. I'd almost never do this:
  1. someClass.mSomeVar = ...
...unless I am actually inside the "someClass" class type, as the private "mSomeVar" would not be accessible otherwise. By the same logic, I'd never do this either:
  1. someClass._someVar = ...
as again, _someVar would be private and inaccessible. To access private data, public or internal properties should be added instead.