Author Topic: Confused with Target.Broadcast  (Read 3162 times)

Rogdor

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 14
    • View Profile
Confused with Target.Broadcast
« on: December 09, 2013, 08:53:27 PM »
I'm trying to implement a global chat, across multiple channels. I thought that's what Target.Broadcast would do, but it appears to only work within the current channel.

Am I just misunderstanding what Target.Broadcast is for? Is it working as intended? Or possibly I'm just using it wrong somehow.

Edit: Seems to be a bug. See below.
« Last Edit: December 09, 2013, 10:45:58 PM by Rogdor »

Rogdor

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Confused with Target.Broadcast
« Reply #1 on: December 09, 2013, 09:14:48 PM »
Okay here's the exception I'm getting when a player changes to a different channel and tries to use Target.Broadcast. If they are in the same channel it works fine.

  1. Exception has been thrown by the target of an invocation.
  2. LoginData.GlobalChat (System.Int32, System.String)
  3. UnityEngine.Debug:LogError(Object)
  4. TNet.UnityTools:PrintException(Exception, CachedFunc, Object[]) (at Assets/TNet/Client/TNUnityTools.cs:83)
  5. TNet.UnityTools:ExecuteAll(List`1, String, Object[]) (at Assets/TNet/Client/TNUnityTools.cs:192)
  6. TNObject:Execute(String, Object[]) (at Assets/TNet/Client/TNObject.cs:316)
  7. TNObject:FindAndExecute(UInt32, String, Object[]) (at Assets/TNet/Client/TNObject.cs:361)
  8. TNManager:OnForwardedPacket(BinaryReader) (at Assets/TNet/Client/TNManager.cs:822)
  9. TNet.GameClient:ProcessPacket(Buffer, IPEndPoint) (at Assets/TNet/Client/TNGameClient.cs:684)
  10. TNet.GameClient:ProcessPackets() (at Assets/TNet/Client/TNGameClient.cs:627)
  11. TNManager:Update() (at Assets/TNet/Client/TNManager.cs:834)

My code goes like this:

  1. tno.Send("GlobalChat", Target.Broadcast, TNManager.playerID, text);
  1.         [RFC]
  2.         void GlobalChat(int playerID, string text) {
  3.                 if (chatList != null) {
  4.                         Player talkingPlayer = TNManager.GetPlayer(playerID);
  5.                         chatList.Add("[00FF00]" + talkingPlayer.name + ": [-]" + text);
  6.                 }
  7.         }
  8.  

Which is on a TNBehaviour script on the same object as my TNManager.

Edit: I'm using 1.8.2b
« Last Edit: December 09, 2013, 09:40:03 PM by Rogdor »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Confused with Target.Broadcast
« Reply #2 on: December 10, 2013, 01:36:36 AM »
"Exception has been thrown by the target of an invocation." means that there was an exception in your function that caused it to exit. My guess it's this:
  1. Player talkingPlayer = TNManager.GetPlayer(playerID);
You use the talkingPlayer without checking to see if it's null.

When you're not in a channel, there are no players.

Rogdor

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Confused with Target.Broadcast
« Reply #3 on: December 10, 2013, 09:09:23 AM »
Ahh. Thanks. I think I'm also just bucking up too much against TNet's paradigm of channels. I'm going to rethink my need for global broadcasts altogether.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Confused with Target.Broadcast
« Reply #4 on: December 10, 2013, 11:35:12 PM »
Since all you need is the player's name, simply pass it along with your RFC call.
  1. [RFC] void GlobalChat(string playerName, string text)