Author Topic: RFC Not Being Called  (Read 7723 times)

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
RFC Not Being Called
« on: February 18, 2013, 08:05:26 PM »
The following RFC is never called. The log message "Color should be changed" never appears. What am I doing wrong? I know that SetUpPlayer is being called because the log message is appearing from in there. But SetColor is never called.

  1. [RequireComponent(typeof(TNObject))]
  2. public class PlayerCapsule : TNBehaviour {
  3.  
  4.         void Awake() {
  5.                 if (TNManager.isThisMyObject) {
  6.                         gameObject.AddComponent<Controls>();
  7.                         SetUpPlayer();
  8.                 }
  9.         }
  10.  
  11.         void SetUpPlayer() {
  12.                 ColorHSV col = new ColorHSV(Random.Range(0f, 1f), 0.5f, 0.5f);
  13.                 Debug.Log("Color is setup as " + col.ToString());
  14.                 tno.Send("SetColor", Target.AllSaved, col.ToColor());
  15.         }
  16.  
  17.         [RFC]
  18.         void SetColor(Color col) {
  19.                 renderer.material.color = col;
  20.                 Debug.Log("Color should be changed.");
  21.         }
  22. }
  23.  

I'm really stumped. I don't know why this isn't working. The even stranger thing is that this did work properly, before I added the object to the TNManager Object List. . .
« Last Edit: February 18, 2013, 09:16:01 PM by Deozaan »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFC Not Being Called
« Reply #1 on: February 18, 2013, 08:52:32 PM »
Try using tno.isMine instead of TNManager.isThisMyObject, and do the SetUpPlayer logic in Start() rather than awake.

Btw, why call this function via RFC anyway? You're calling it on all clients.. and the value is the same. You might as well just set the renderer material's color in the Start function as-is.

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: RFC Not Being Called
« Reply #2 on: February 18, 2013, 09:41:17 PM »
Try using tno.isMine instead of TNManager.isThisMyObject, and do the SetUpPlayer logic in Start() rather than awake.

Btw, why call this function via RFC anyway? You're calling it on all clients.. and the value is the same. You might as well just set the renderer material's color in the Start function as-is.

Moving SetUpPlayer into Start() fixed the RFC not being called.

If it isn't obvious, I really have no idea what I'm doing as far as the networking goes. What I'm trying to do is simply spawn a capsule for each player that joins the scene/level/channel and give it a random color, and give it controls only for the player it belongs to.

I have the capsule spawning. But joining the channel multiple times causes more and more and more of them to be spawned. For some reason this code isn't despawning them, or actually, it is sometimes, but there is always at least one extra one one:

  1.         void OnNetworkPlayerLeave(Player pl) {
  2.                 if (TNManager.isHosting && pl.id == TNManager.objectOwnerID) {
  3.                         TNManager.Destroy(gameObject);
  4.                 }
  5.         }
  6.  
  7.         void OnNetWorkLeaveChannel() {
  8.                 if (tno.isMine) {
  9.                         TNManager.Destroy(gameObject);
  10.                 }
  11.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFC Not Being Called
« Reply #3 on: February 19, 2013, 08:58:10 AM »
OnNetworkLeaveChannel is sent to you after you've left the channel, so destroying the object at that point isn't going to be very effective. Instead, use OnNetworkPlayerLeave -- on the host, find the object that was created by the player and destroy it.

danreid70

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: RFC Not Being Called
« Reply #4 on: February 19, 2013, 09:08:13 PM »
ahHA! Figured out one other thing I'm doing wrong - not using RFCs correctly - what is the best way to call an RFC (using JS?)... I keep getting an error:
...BCE0005: Unknown identifier: 'Target'.

I'm sure it's because I'm using JS and not CS... I have TNet in the Plugins folder, so it should compile "correctly"... Not sure what I'm doing wrong - this looks as if it should work. Anyone else out there using JS and have this happen with .Send?

I have for example:
  1. var tno:TNObject;
  2. function Start() {
  3.         tno = GetComponent(TNObject);
  4. }
  5.  
  6. //
  7. //and in a later function, where I'm firing a weapon:
  8. //
  9. //    if (tno.isMine){
  10. //        tno.Send("FireWeapon",Target target,1.0f);
  11. //    }
  12. //
  13.  
  14. @RPC
  15. function FireWeapon(n:float) {
  16.     //blah blah blah code here
  17. }
  18.  
  19.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFC Not Being Called
« Reply #5 on: February 19, 2013, 10:46:36 PM »
You have it tagged as @RPC. You should tag it as @RFC instead. "Target target" is also invalid.

tno.Send("FireWeapon",TNet.Target.All,1.0f);

danreid70

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: RFC Not Being Called
« Reply #6 on: February 20, 2013, 06:31:18 PM »
Aw cr@p. I think I'm going to have problems with this. :( I'm writing all my code in JS - and JS has @RPC.
TNet is written in CS - and CS uses [RFC]...

So I need to use @RPC for my java"script" code - or I have to convert all my stuff to CS -- which I really don't want to even attempt.

OR. As is possibly the case - I'm doing something obviously wrong (again). Believe me, I keep reading through the forums here and on UnityForums - and am slowly making progress without asking too many questions... (I hope... :D).

Has anyone out there gotten tno.Send(...) with an @RPC function in JS to work? Maybe I'm just missing something...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFC Not Being Called
« Reply #7 on: February 20, 2013, 07:23:35 PM »
If you put TNet into the Plugins folder, you will be able to use @RFC prefix just fine.

danreid70

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: RFC Not Being Called
« Reply #8 on: February 20, 2013, 07:57:49 PM »
I tried - I have the TNet folder inside Plugins  folder (I upgraded to new version of TNet a night or two ago - moved the TNet folder back out of plugins first - back into root - then upgraded, then moved it back to Plugins folder). I always do that because I found that some installs overwrite things weirdly during updates if they're not in the originally installed location... After upgrade, I moved TNet folder back into Plugins folder (where it sits happily with it's friend, the NGUI folder) :D

All the other functions work great in TNet - I'm figuring out quite a bit more and revamping my code now that I'm "seeing the light" and some of this is making more sense now.  Hell, a LOT of it is making more sense the more I play with it, and read more and more new posts (by the way, your attention to customers on your forum is unbelievable! - you always have an answer, and most times you answer someone's question, it answers another question I haven't thought to ask yet! hehe).

So anyway - if I change my javascript to "@RFC" I get this:
Assets/_SCRIPTS/_SHIP_CONTROLS.js(180,2): BCE0064: No attribute with the name 'RFC' or 'RFCAttribute' was found (attribute names are case insensitive). Did you mean 'System.Security.Cryptography.Rfc2898DeriveBytes'?

If I make it "@RPC", the function never gets called - (my "FireWeapon()" function as above). I even put a Debug.Log right before I call it to ensure I get to it, and the tno.Send(...) is getting called. But the Debug.Log that I put in the first line of my @RPC ... function FireWeapon(...){... never gets called.

It's weird. @RFC causes an error, and @RPC never gets called.

And I have TNet in the Plugins folder.

Anything else I might be doing wrong?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFC Not Being Called
« Reply #9 on: February 20, 2013, 08:53:05 PM »
Ah. Use TNet.RFC instead of just RFC.

danreid70

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: RFC Not Being Called
« Reply #10 on: February 20, 2013, 10:34:00 PM »
 :) :) :) and THAT is why I'll buy every asset Aren creates! Awesome! Thanks again Aren!  8) 8) 8)
I'll try that tomorrow night - I'm going to have to compile a list of all these answers you've given me. Especially for developers using JS. I might even be able to simplify my launch, create, RFC code in JS into a short sample that you could check over and use in a tutorial. Maybe this weekend. Might save you some time and would certainly help others hitting the same bumps I've hit. TNet really is friggin slick!!!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFC Not Being Called
« Reply #11 on: February 21, 2013, 04:30:05 AM »
:)