Author Topic: Following youtube game from scratch  (Read 3102 times)

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
Following youtube game from scratch
« on: April 08, 2013, 03:28:05 PM »
Following this: http://www.youtube.com/watch?v=cTjy-L8C6WM

I've copied the ExampleMenu from TNet and created my own MainMenu and once you "Connect" you can then click a button to join channel 1 and load the game scene. The game scene is copied from the above video.

In my MainMenu I have this:
  1. void OnApplicationQuit()
  2.         {      
  3.                 if (TNServerInstance.isActive) {
  4.                         TNServerInstance.Stop("SA_Server.dat");
  5.                 }
  6.                 if (TNManager.isConnected)
  7.                         TNManager.Disconnect();
  8.         }
  9.  

If I quit the "server" while it's active and I connected with my other computer I can see an entry in SA_Server.dat titled "OnSetTarget" and some binary data. When this happens and I run the app again and restart the server it will create a ghost or phantom player and if there's two of those "OnSetTarget" entries in the saved file I will get TWO phantom player capsules.

Seriously... how could I screw up such a simple tutorial? Should I not be saving the server file?

Contents of saved .dat file:
  1. Game¸ˇˇˇˇ˛ˇˇ#'˛ˇˇ OnSetTargeti…π¿á6µ¿¸ˇˇ#'¸ˇˇ OnSetTargetil£@"˚”¿˛ˇˇÄ?¸ˇˇÄ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Following youtube game from scratch
« Reply #1 on: April 08, 2013, 05:02:12 PM »
Target.AllSaved means the message will be saved in the channel.

When joining a channel you specify whether the channel's contents should be persistent or not. If they are persistent, the channel's RFC calls will be saved when the server shuts down, and loaded back up when the server is started up again.

You choose to save the server's contents, meaning everything you create / save in the channel will still be there the next time you start it up.

Either don't save it, or remove the RFC call when the player leaves. To remove a call, do it on the remaining player rather than on the player that leaves (in OnNetworkPlayerLeave). Basically the Host should clean up after the player that just left.

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
Re: Following youtube game from scratch
« Reply #2 on: April 09, 2013, 10:08:31 AM »
Target.AllSaved means the message will be saved in the channel.

When joining a channel you specify whether the channel's contents should be persistent or not. If they are persistent, the channel's RFC calls will be saved when the server shuts down, and loaded back up when the server is started up again.

You choose to save the server's contents, meaning everything you create / save in the channel will still be there the next time you start it up.

Either don't save it, or remove the RFC call when the player leaves. To remove a call, do it on the remaining player rather than on the player that leaves (in OnNetworkPlayerLeave). Basically the Host should clean up after the player that just left.

First - THANK-YOU again.... oh if I could have about 10 minutes inside your head :)

I added the OnNetworkPlayerLeave (Player) to the GamePlayer script, perhaps that was the wrong place but if I disconnected everything and then shutdown the server it worked fine, every restart there were no phantom players. However when I just quit the app that was running the server those OnNetworkPlayerLeave calls didn't happen and my OnApplicationQuit did its job and saved the server which sounds right to me.

So... I created a new join method and added the persistent bool as a third option. This will allow "real clients" to join and not persist but if or rather when I add NPC's those should persist until the server removes them.

And to think I was all proud of my small tweak of blue player = yours and yellow player(s) opponents.... I'm sure this won't be the end of my questions and best of luck with your new game!