Author Topic: [SOLVED] Saved RFC Isn't Working.  (Read 2909 times)

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
[SOLVED] Saved RFC Isn't Working.
« on: November 23, 2015, 04:41:12 PM »
In my script I have an int which equals 0. When a player connects if that int is still equal to 0 they send an RFC that is set to Target.AllSaved to set the int to 1.

Here's is my script:
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4. using TNet;
  5.  
  6. public class MapLoader : TNBehaviour {
  7.  
  8.     int intToSave;    
  9.  
  10.     void Start ()
  11.     {
  12.         InvokeRepeating("CheckConnection", 0, 2);
  13.     }
  14.  
  15.     void CheckConnection ()
  16.     {
  17.         if(TNManager.isInChannel)
  18.         {
  19.             CancelInvoke("CheckConnection");
  20.  
  21.             if(intToSave == 0)
  22.             {
  23.                 print("intToSave has the default value");
  24.  
  25.                 tno.Send("SaveInt", Target.AllSaved, 1);
  26.  
  27.                 print("intToSave is now: " + intToSave);
  28.             }
  29.             else
  30.             {
  31.                 print("intToSave is: " + intToSave);
  32.             }
  33.         }
  34.     }
  35.  
  36.     [RFC]
  37.     void SaveInt (int number)
  38.     {
  39.         intToSave = number;
  40.     }
  41. }

Here is what I want to happen:  :)
- Player A connects and sets intToSave = 1
- Player A disconnects
- Player X connects later and can still see intToSave is = 1

Here is what actually happens:  :(
- Player A connects and sets intToSave = 1
- Player A disconnects
- Player X connects later and intToSave is = 0 for some reason

It seems like the RFC to update intToSave gets deleted when the player that called it disconnects.

Any suggestions?   ???
Thanks.
« Last Edit: November 24, 2015, 11:52:09 AM by doomlazy »

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Saved RFC Isn't Working.
« Reply #1 on: November 23, 2015, 06:32:19 PM »
You're calling CancelInvoke("CheckConnection"); right after you enter your if statement. Wont that cancel it and not continue to the code below?

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
Re: Saved RFC Isn't Working.
« Reply #2 on: November 24, 2015, 02:47:55 AM »
If that was the case then I shouldn't be getting the print messages but I do :P

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Saved RFC Isn't Working.
« Reply #3 on: November 24, 2015, 04:35:15 AM »
When a player leaves, any networked objects created by that player are destroyed, along with any RFCs residing on those objects.
Additionally, all RFCs are cleared if the channel is not persistent and the last player leaves.

So make sure the RFC you're calling is on an object that won't be destroyed when Player A leaves, and make sure the channel is set to persistent.

Most of the relevant code is in TNChannel.cs.
The part that saves the RFC is in TNGameServer.cs in the ProcessForwardPacket function.

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
Re: Saved RFC Isn't Working.
« Reply #4 on: November 24, 2015, 06:03:13 AM »
I am not at home right now so I can't try it but I think my problem was that I forgot to make the channel persistent.
Thanks! :D

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
Re: Saved RFC Isn't Working.
« Reply #5 on: November 24, 2015, 11:51:30 AM »
Ok I fixed my problem by making the channel is persistent.
Thanks!  :D