Author Topic: Need simple example to save channel data  (Read 6691 times)

krvc

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 16
    • View Profile
Need simple example to save channel data
« on: October 26, 2016, 07:07:20 AM »
Hi, i connect to my project with TNAutoJoin. I change "public bool persistent"  to "true";

I create 2 buttons - Set version and Get version. I save info TNManager.SetServerData, it saved, but all my players need to save data, and i change it to SetChannelData, it save too, but after i disconnect all data a missing.... (not saving)


using UnityEngine;
using System.Collections;
using TNet;

public class GameVersion : MonoBehaviour {
    private int checkVersion;
   
    //SET SERVER VERSION
    public void SetServerGameVersion () {
        TNManager.SetChannelData("game version", 20161026);
    }


    //GET SERVER VERSION
    public void GetGameVersion()
    {
        checkVersion = TNManager.GetChannelData<int>("game version");
        print(checkVersion);
    }
}

krvc

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Need simple example to save channel data
« Reply #1 on: October 27, 2016, 02:11:42 AM »
Hmm.. i think i not needed all time save channel data in server.
I need added "IF" and check empty data or not when connect to channel, if empty then again Write.
Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Need simple example to save channel data
« Reply #2 on: October 30, 2016, 12:57:16 PM »
SetServerData can only be called by the server's administrator. Channel data can be set by anyone in that channel.

You aren't actually specifying which channel to use there... TNManager.SetChannelData(channelID, "name", value) is what you should be using.

krvc

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Need simple example to save channel data
« Reply #3 on: November 03, 2016, 01:16:57 AM »
   try to count players on channel or something else, but something wrong
       
                int playersCounter;
                playersCounter = TNManager.GetChannelData<int>(0, "playersOnServer") +1;
                TNManager.SetChannelData(0, "playersOnServer", playersCounter);
                print("1counterSet" + playersCounter);

                playersCounter = TNManager.GetChannelData<int>(0, "playersOnServer");
                print("2counterGet" + playersCounter);

print1 = 1  print2 = 0

krvc

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Need simple example to save channel data
« Reply #4 on: November 03, 2016, 03:14:56 AM »
I think i not connected... Try to set data after  TNManager.JoinChannel(0, firstLevel, persistent, 10000, null);. Maybe  TNManager.JoinChannel need time.
Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Need simple example to save channel data
« Reply #5 on: November 03, 2016, 08:28:20 AM »
Of course it does. It's the case with every single TNet call. They are all delayed, never immediate. You need to wait for the channel join notification. Subscribe to TNManager.onJoinChannel.