Author Topic: Soup to nuts for saving player data to the server  (Read 4069 times)

harko12

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Soup to nuts for saving player data to the server
« on: September 11, 2016, 08:54:14 PM »
Hi there.  I've been struggling for days now trying to get my server to save and then re-load the player data that I'm setting for my player.  I have read all the posts I can find, and followed the advice, but still it doesn't work.

Can somebody post from connect to disconnect what steps you would have to take to create a player save file, save data, then reload it next time you connected?  Maybe what I'm missing will jump out at me. 

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Soup to nuts for saving player data to the server
« Reply #1 on: September 11, 2016, 10:27:15 PM »
When you connect to the server, call TNManager.Load("filename");

That's it. TNet automatically saves all player data back into the same file. All you need to do is use TNManager.SetPlayerData to set values, and TNManager.GetPlayerData to retrieve them.

harko12

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Soup to nuts for saving player data to the server
« Reply #2 on: September 11, 2016, 11:25:12 PM »
I had tried it a couple ways, using load, not using load.  I fell into the trap of trying more than one new thing at once, and switched over to TNManager.player.Get<>() for my gets, and sets, and I think that was where I went wrong.  Those behave different than the TNManager.GetPlayerData() methods, and don't seem to force a save of the file.

I managed to get it all going now, but doing the TNManager.SetPlayerSave() then starting a coroutine to wait for that callback to come back, then looking for the player data I want, it seems to be working.

Thanks for the reply!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Soup to nuts for saving player data to the server
« Reply #3 on: September 13, 2016, 11:18:58 AM »
Each player can only alter their own player data using TNManager.SetPlayerData. Modifying the local player.dataNode will have no effect as it will just get overwritten the next time an update comes from the server.

There is no need to start a coroutine to wait for anything. You get notified when player data arrives: TNManager.onSetPlayerData.