Author Topic: [SOLVED] RFCs looping, freezes TNet stack and Unity  (Read 4440 times)

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
[SOLVED] RFCs looping, freezes TNet stack and Unity
« on: October 20, 2014, 12:45:57 AM »
Alright, so here I am trying to make a Networked Kill Feed, so when someone frags the other player, it registers up in the frag list. This is the base script for that killfeed:
  1. public List<string> fragFeed = new List<string>();
  2.  
  3.     void OnGUI()
  4.     {
  5.         // The frag feed.
  6.         GUILayout.BeginArea(new Rect(Screen.width - 320, Screen.height - (amtOfFragsShown * 24), 310, (amtOfFragsShown * 24)));
  7.         GUILayout.BeginVertical();
  8.  
  9.         for (int i = 0; i > amtOfFragsShown; i++)
  10.         {
  11.             GUILayout.Box(fragFeed[i]);
  12.         }
  13.  
  14.         GUILayout.EndVertical();
  15.         GUILayout.EndArea();
  16.     }
  17.  
  18.     [RFC]
  19.     void AnnouncePlayerAction(string whatHappened)
  20.     {
  21.         Debug.Log("Got a player announcement...");
  22.         fragFeed.Add(whatHappened);
  23.     }
  24.  

In the appropriate scripts, I have this. This is taken from the player vitals script, which is basically the "heart" of the player - if they die, it does all the required things on death (respawn, ragdoll, etc). This function is the one that gets triggered when you take the easy way out or you fall into the void and the level OOB triggers hit the character.

  1. // ......
  2.    private void KillSelf()
  3.     {
  4.         AnnouncePlayerAction(TNManager.playerName + " ended it all");
  5.         currHealth = 0;
  6.     }
  7.  
  8.     [RFC]
  9.     void AnnouncePlayerAction(string whatHappened)
  10.     {
  11.         Debug.Log("Got a player announcement...");
  12.         to.Send("AnnouncePlayerAction", Target.All, whatHappened);
  13.         // fragFeed.Add(whatHappened);
  14.     }
  15.  

However, the issue here is that it loops itself and basically freezes Unity or the Unity Player, requiring a Task Manager to kill the process. Basically, I want to have one script fire the RFC to "announce" the event, and then the other script, which is the Network Feed script, to pick up the message, add it to the list, and then go from there.

Could you assist?
« Last Edit: October 22, 2014, 12:14:56 AM by MCoburn »

ldw-bas

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 2
  • Posts: 32
    • View Profile
Re: RFCs looping, freezes TNet stack and Unity
« Reply #1 on: October 20, 2014, 02:58:38 AM »
You should separate the sending of your RFC and the actual action from eachother. A basic rule of thumb would be to never invoke an [RFC] yourself only do it with to.Send.

So something like this:
  1. // ......
  2.    private void KillSelf()
  3.     {
  4.         RequestAnnouncePlayerAction(TNManager.playerName + " ended it all");
  5.         currHealth = 0;
  6.     }
  7.  
  8.     void RequestAnnouncePlayerAction(string whatHappened)
  9.     {
  10.         to.Send("AnnouncePlayerAction", Target.All, whatHappened);
  11.     }
  12.  
  13.     [RFC]
  14.     void AnnouncePlayerAction(string whatHappened)
  15.     {
  16.         Debug.Log("Got a player announcement...");
  17.         // fragFeed.Add(whatHappened);
  18.     }
  19.  

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: RFCs looping, freezes TNet stack and Unity
« Reply #2 on: October 20, 2014, 08:48:27 PM »
Okay, that works, but I want the void to be fired on the NetworkKillFeed script, not the same player script. It works as intended so far, but the NetworkKillFeed doesn't show up the entry as the RFC only gets fired on the playervitals script.

How do I get the script to trigger the RFC on that KillFeed script so it can add it to the log?
« Last Edit: October 20, 2014, 09:31:35 PM by MCoburn »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFCs looping, freezes TNet stack and Unity
« Reply #3 on: October 21, 2014, 12:08:41 AM »
When you send an RFC, it will be called on the same TNObject. If you want to call an RFC on a different TNObject, then do just that -- it's like calling a function on a different component.

P.S. Why do you do the "to.Send" instead of using the built-in "tno.Send"? Make sure your script derives from TNBehaviour.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: RFCs looping, freezes TNet stack and Unity
« Reply #4 on: October 21, 2014, 12:21:28 AM »
When you send an RFC, it will be called on the same TNObject. If you want to call an RFC on a different TNObject, then do just that -- it's like calling a function on a different component.

P.S. Why do you do the "to.Send" instead of using the built-in "tno.Send"? Make sure your script derives from TNBehaviour.
The scripts are MonoBehaviours. So if I replace that with TNBehaviour, it should be okay?

What a really wanted was a independent gameobject handling UI elements like scoreboard, etc. So that means to get the RFCs, I would need to assign the game object a TNObject ID, no? I'm confused...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFCs looping, freezes TNet stack and Unity
« Reply #5 on: October 21, 2014, 12:38:44 AM »
Yes, and yes. TNBehaviour is just a MonoBehaviour with a convenient set of functions/properties.

You must always have a TNObject in order to send messages. What I generally do is have a static TNObject already present in the scene from the start -- with ID of #1. I put all my generic scripts there -- game manager, team manager, game chat, etc. When I want to send a chat message for example, I do GameChat.Send, which does GameChat.instance.tno.Send(...) inside, calling an RFC that's a function inside the GameChat script.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: RFCs looping, freezes TNet stack and Unity
« Reply #6 on: October 21, 2014, 01:00:42 AM »
Yes, and yes. TNBehaviour is just a MonoBehaviour with a convenient set of functions/properties.

You must always have a TNObject in order to send messages. What I generally do is have a static TNObject already present in the scene from the start -- with ID of #1. I put all my generic scripts there -- game manager, team manager, game chat, etc. When I want to send a chat message for example, I do GameChat.Send, which does GameChat.instance.tno.Send(...) inside, calling an RFC that's a function inside the GameChat script.

Ah, I see... I might do the same and see how it goes.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: RFCs looping, freezes TNet stack and Unity
« Reply #7 on: October 22, 2014, 12:12:02 AM »
Everything working as expected now - I'm using Unity GUI (from 4.6 Beta) to do the action log. Can confirm that the messages are broadcast and each client shows the messages on the screen. Thanks for the assistance.