Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: krvc on October 26, 2016, 07:07:20 AM

Title: Need simple example to save channel data
Post by: krvc 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);
    }
}
Title: Re: Need simple example to save channel data
Post by: krvc 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.
Title: Re: Need simple example to save channel data
Post by: ArenMook 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.
Title: Re: Need simple example to save channel data
Post by: krvc 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
Title: Re: Need simple example to save channel data
Post by: krvc 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.
Title: Re: Need simple example to save channel data
Post by: ArenMook 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.