Author Topic: "Unable to execute function 'OnChat'. Did you forget an [RFC] prefix, perhaps?"  (Read 7317 times)

Etarnalazure

  • Guest
Hey again!

I've started getting this error, and I have no idea why!

I mean, its its right there!

  1. protected override void OnSubmit (string text)
  2.         {
  3.                
  4.                 tno.Send("OnChat", Target.All, TNManager.playerID, text);
  5.         }
  6.  
  7.         [RFC]
  8.         void OnChat (int playerID, string text)
  9.         {
  10.                 Color color = Color.white;
  11.                 Player sender = TNManager.GetPlayer(playerID);
  12.  
  13.                 if (sender != null)
  14.                 {
  15.                         // If the message was not sent by the player, color it differently and play a sound
  16.                         if (playerID != TNManager.playerID)
  17.                                 color = new Color(0.6f, 1.0f, 0f);
  18.  
  19.                         // Embed the player's name into the message
  20.                         text = string.Format("[{0}]: {1}", sender.name, text);
  21.                 }
  22.                 Add(text, color);
  23.  
  24.                 if (notificationSound != null)
  25.                         NGUITools.PlaySound(notificationSound);
  26.         }
  27.  

As you can see, the RFC is right there.

So, I dont really understand why its giving me that error.

Full Error:
  1. Unable to execute function 'OnChat'. Did you forget an [RFC] prefix, perhaps?
  2. UnityEngine.Debug:LogError(Object, Object)
  3. TNObject:FindAndExecute(UInt32, String, Object[]) (at Assets/Tools/TNet/Client/TNObject.cs:459)
  4. TNObject:SendRFC(UInt32, Byte, String, Target, Boolean, Object[]) (at Assets/Tools/TNet/Client/TNObject.cs:658)
  5. TNObject:Send(String, Target, Object[]) (at Assets/Tools/TNet/Client/TNObject.cs:523)
  6. UIGameChat:OnSubmit(String) (at Assets/NGUI/Scripts/Custom/UI/UIGameChat.cs:45)
  7. UIChat:OnSubmitInternal(String) (at Assets/NGUI/Scripts/Generic/UI/UIChat.cs:129)
  8. UIInput:Append(String) (at Assets/NGUI/Scripts/UI/UIInput.cs:417)
  9. UIInput:OnInput(String) (at Assets/NGUI/Scripts/UI/UIInput.cs:385)
  10. UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
  11. UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:679)
  12. UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:820)
  13.  

pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
If this is a static object, rebuild the object.  Not sure why atm but it seams that some times static objects get stuck in not noticing their [RFC]'s.  If it works for you please post as you will be at least the 3rd person that has this issue.  Also if this does fix the issue did you have a prior version of TNET and upgrade recently?

Etarnalazure

  • Guest
Its not static, though I did build it anyway just to make sure, didnt work.

I checked for updates, there were none. The weird thing is.. It worked yesterday, I havent touched the script since..

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Check the IDs of your TNObjects in the scene. Chances are you have more than one with the same ID, so it's going to the wrong object.

P.S. Modify the Debug.Logs in the two FindAndExecute functions like so for additional info:
  1. Debug.LogError("Unable to execute function with ID of '" + funcID + "'. Make sure there is a script that can receive this call.\n" +
  2.         "GameObject: " + GetHierarchy(obj.gameObject), obj.gameObject);
  1. Debug.LogError("Unable to execute function '" + funcName + "'. Did you forget an [RFC] prefix, perhaps?\n" +
  2.         "GameObject: " + GetHierarchy(obj.gameObject), obj.gameObject);

Etarnalazure

  • Guest
Changed the ID to something I know for sure is not used, same deal.

I put in the new debug info as well;
  1. Unable to execute function 'OnChat'. Did you forget an [RFC] prefix, perhaps?
  2. GameObject: "Camera/Chat/ChatWindow"
  3. UnityEngine.Debug:LogError(Object, Object)
  4. TNObject:FindAndExecute(UInt32, String, Object[]) (at Assets/Tools/TNet/Client/TNObject.cs:464)
  5. TNObject:SendRFC(UInt32, Byte, String, Target, Boolean, Object[]) (at Assets/Tools/TNet/Client/TNObject.cs:664)
  6. TNObject:Send(String, Target, Object[]) (at Assets/Tools/TNet/Client/TNObject.cs:529)
  7. UIGameChat:OnSubmit(String) (at Assets/NGUI/Scripts/Custom/UI/UIGameChat.cs:45)
  8. UIChat:OnSubmitInternal(String) (at Assets/NGUI/Scripts/Generic/UI/UIChat.cs:129)
  9. UIInput:Append(String) (at Assets/NGUI/Scripts/UI/UIInput.cs:417)
  10. UIInput:OnInput(String) (at Assets/NGUI/Scripts/UI/UIInput.cs:385)
  11. UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
  12. UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:679)
  13. UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:820)
  14.  

Etarnalazure

  • Guest
The rest of the RFC's work though..

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
So Camera/Chat/ChatWindow game object has the script that has the [RFC] void OnChat() function? And that's the exact same object with the TNObject on it? And it doesn't have a parent object with a TNObject on it?

Etarnalazure

  • Guest

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Curious. Well, something is building its list of RFCs before all of them are present.

Do this: open TNBehaviour and change the 'tno' function to this:
  1.         public TNObject tno
  2.         {
  3.                 get
  4.                 {
  5.                         if (mTNO == null)
  6.                         {
  7.                                 mTNO = GetComponent<TNObject>();
  8.                                 if (mTNO != null) mTNO.rebuildMethodList = true;
  9.                         }
  10.                         return mTNO;
  11.                 }
  12.         }

Etarnalazure

  • Guest
Nope, still wont work.

Besides, all the other RFC's work just fine. Could it be the script?

I'll post the entirety of the script. It should largely be the same as the one from Starlink except that I'm using pixelSize instead of size.

  1. using UnityEngine;
  2. using TNet;
  3.  
  4. /// <summary>
  5. /// Networked chat logic. Takes care of sending and receiving of chat messages.
  6. /// </summary>
  7.  
  8. [RequireComponent(typeof(TNObject))]
  9. public class UIGameChat : UIChat
  10. {
  11.         TNObject tno;
  12.  
  13.         /// <summary>
  14.         /// Sound to play when a new message arrives.
  15.         /// </summary>
  16.  
  17.         public AudioClip notificationSound;
  18.  
  19.         /// <summary>
  20.         /// If you want the chat window to only be shown in multiplayer games, set this to 'true'.
  21.         /// </summary>
  22.  
  23.         public bool destroyIfOffline = false;
  24.  
  25.         /// <summary>
  26.         /// We want to listen to input field's events.
  27.         /// </summary>
  28.  
  29.         void Start ()
  30.         {
  31.                 if (destroyIfOffline && !TNManager.isInChannel)
  32.                 {
  33.                         Destroy(gameObject);
  34.                 }
  35.                 else tno = GetComponent<TNObject>();
  36.         }
  37.  
  38.         /// <summary>
  39.         /// Send the chat message to everyone else.
  40.         /// </summary>
  41.  
  42.         protected override void OnSubmit (string text)
  43.         {
  44.                 tno.Send("OnChat", Target.All, TNManager.playerID, text);
  45.         }
  46.  
  47.         [RFC]
  48.         void OnChat (int playerID, string text)
  49.         {
  50.                 Color color = Color.white;
  51.                 Player sender = TNManager.GetPlayer(playerID);
  52.  
  53.                 if (sender != null)
  54.                 {
  55.                         // If the message was not sent by the player, color it differently and play a sound
  56.                         if (playerID != TNManager.playerID)
  57.                                 color = new Color(0.6f, 1.0f, 0f);
  58.  
  59.                         // Embed the player's name into the message
  60.                         text = string.Format("[{0}]: {1}", sender.name, text);
  61.                 }
  62.                 Add(text, color);
  63.  
  64.                 if (notificationSound != null)
  65.                         NGUITools.PlaySound(notificationSound);
  66.         }
  67.  
  68.         void OnNetworkPlayerJoin  (Player p) { Add(p.name + " has joined the game."); }
  69.         void OnNetworkPlayerLeave (Player p) { Add(p.name + " has left the game."); }
  70. }
  71.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
It doesn't work with that script because it's not derived from TNBehaviour. See how in Start it gets the TNObject component manually? When you do that, you also have to do tno.rebuildMethodList = true;

Etarnalazure

  • Guest
Yeps, works now :)

swizzersweet

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 6
    • View Profile
Was pulling my hair out on this one. Also make sure your visibility modifier let's TNET find your function. Eg, a private method won't be able to be called