Much Ado About Online Multiplayer

So first off I am quite new to Photon , so these may be dumb questions.
But I am having a hard time converting my game from local multi player (pass along play) to online multiplayer.

This is how the game operates locally;
I have a turnmanager which instantiates a Player 1 or Player 2 prefab based on a state (there can be only 2 players)

Now through a human equivalent of an infinite amount of monkeys with an infinite amount of typewriters, I managed to have a playfab login and connect that to Photon, I can create rooms and add players ... but that's where the fun begins.

Both players load into the same scene, but they seem to operate as separate instances... for instance when the game starts I have a randomized first turn ...and so it happens that on one device it is Player 1's turn and on the other it's player 's 2... instead of both loading the same playerturn ....yet they do load into the same scene.

Sometimes they can be controlled separately from each other and other times they both can't be moved ... which leads me to think that there is an ownership issue.... problem is that I don't know how to set this.

Ideally I just want the Masterclient aka the first in the room to be Player 1 and the other Player 2 ... but how do I connect that to the instantiated Player 1 and Player 2 prefab?

I have read many articles and followed a fair few tutorials , but as I have been at it for 10 hours straight , I need a fresh pair of eyes, so any help would be appreciated.

Anyway this is the relevant code:
PhotonConnection : https://pastebin.com/WdfA8YhC
TurnManager: https://pastebin.com/XGBQ2cQM
Player Script (P2 is similar safe for some transform differences): https://pastebin.com/HbjDihBP

Comments

  • Did you find the PUN Basics Tutorial? Read and code it along. This usually helps.
    I would suggest the players instantiate their own items / characters. This solves control issues.
    For a turn based game, you basically only need to summarize the turn in something "serializable" (e.g. a Hashtable with some info) and send it. The other side will get the event and has to update the state, then start the local player's turn.
  • Hey Tobias,

    Thanks for your reply.

    I am currently a bit further along ... am now in the process of figuring out how to communicate the disabling and enabling (set Active) of objects for both players ... score is synced and turns seem to go smoothly .. so hopefully after a week of misery it will finally work by the end of this weekend :smiley:

    I followed a tutorial and read through your documentation ... I have to say though that I find it strange that there are a million tutorials on how to make yet another tower defense game or flappy bird endless runner clone ... yet dealing with architecture and API's (it took me forever to just get playfab to hook into Photon and the Google Play stuff), took me to some obscure places at times just to find that tiny bit of info I needed .

    Now it might be an idea to partner or even commission some people to create game tutorials /training that incorporate your technology , as even though I am a mediocre programmer at best , I have been around software sales & Marketing for more than a decade.... and I think it is important to make it more accessible for dumb dumbs like me.

    On youtube I found these two very helpful:
    https://www.youtube.com/channel/UC2-tEpkeTgnRcDK19f2EmGQ
    https://www.youtube.com/channel/UCjCpZyil4D8TBb5nVTMMaUw

    And teaching wise I found the teaching style of Jonathan Weinberger very good and straight forward
    https://gamedevhq.com/

    Just a suggestion though :)

    Once again thanks for your reply and have a great weekend
  • Fair point and thanks for the input on tutorials.

    Aside from integrating PlayFab, what other topics do you see in the architecture and APIs domain?

  • Hey Tobias,

    I am not entirely sure what you mean, but if you mean what other topics I would like to see, that aren't discussed much, I would say how to actually make a proper game.

    Because most courses out there just teach you how to build a level ... not how to tie everything together .
    Now again I am by no means an experienced developer, so you might have to take things with a grain of salt.

    But I rather have a training where the game itself isn't that interesting , they could be a pair of cubes just moving around .
    And instead focus on how to structure things , not just the SOLID principles, but also everything surrounding it .

    To be specific I am currently developing my first mobile game (which really is just a passion project gone out of hand) ... shameless plug in case you're interested:

    https://youtube.com/watch?v=si42Y8jG0bk&ab_channel=KingofCrokinole

    Generally speaking I can figure out how to program behaviors ... my problems start when I have to deal with more abstract and architectural type of problems (high school all over again :) ) ... like I want to have people buy "discs" for the online part of our game, but I have no idea how to integrate it within teh game (ie how to connect it).

    I want to create a proper leaderboard and give the person on top "the kings puck"which basically gives them free online play and a different skin

    I know how to create a very basic Playfab login where you fill in a name and get into the game , not how to connect through Gmail/Facebook or any other social media type platform ... and store that data.

    Specific to Photon , I know how to use callbacks and set up a basic join room mechanism and after 7+ days of misery I have something working now ..

    But it's a far cry of what I wanted to make ...
    I wanted people to create "rooms" which stay active for however long the game lasts ( and give people the option to leave , thus ending the game in the opponents favour) and have the possibility for people to make multiple rooms they can exit and enter when an opponent has made their turn/move and set up a notification system to notify people when a move has been made
    Also having the possibility to invite people through Facebook/Instagram and play them .
    And indeed play people globally ... I know there are issues with packet loss and latency, but as I have a turnbased system and not too many moving parts I think it should be doable

    Essentially if I had to break it down to the essentials, I find that many videos/topics stay at this basic level ...and though I am grateful for that information ... I think that if you guys would build a tutorial system around your software that deals with this structure and architecture, it would be the smart thing to do for your business.

    Again I have been in software sales for 10+ years and have seen the likes of Autodesk, Adobe, Apple etc in action and know what they're about.
    And looking at your business, I think you're still on top ... but looking at "the eco system" and the fact that Unity went public (which means they will want to have a system they can control, including multiplayer...of which this MLAPI is the first step) is a sign that you need to make yourself invaluable to new and existing (potential) customers alike.

    And I think part of that strategy should be to offer an accessible and coherent training series on how to structure a game (as most info really is fragmented), where your software is central.
    And I would even include something as pricing strategy and a bit of marketing training on how to push a game.

    Ultimately convenience sells ... so the more accessible you make your software the better it will be.
    Thing is most software companies never get the simple fact that they're not making something for rocket scientists and I often use the example of the mobile phone , when I try to explain this.... as more often than not it takes some convincing to tell brilliant engineers that "dumbing things down" is actually a good thing.

    Everyone can use a smart phone without having to use a manual, if a mobile phone would be difficult to use and you needed to type messages in C++ and compile for 50 minutes in order to call someone or send a text, nobody would own one.
    And the same applies to software ... the less manuals you need , the better ... and the more info that is out there, the better as well.

    If you offer people the infrastructure, or platform /means (which should have a heavy bias to your software) to make a good game (ie a desired end result) then people will flock to your software.

    The manual is nice, but it is very often just a reference guide to people who already know how to build a multiplayer or have knowledge about networks already, but just need to learn your structure/way of doing things ... that is not ...or rather should not be your target audience ... which I perceive to be people like me.

    Small businesses , individuals and perhaps even mid sized companies without a dedicated network engineer, they are the target audience ... offer them a way to easily implement things along a guided tutorial/training materials ...and perhaps even offer additional paid services (i.e. live support ) ... and do more social (Twitch streams/ Discord/Online Game Jams etc).

    Anyway just wanting to pitch and hope it helps





  • Tobias
    Tobias admin
    edited June 2021
    Thanks for pitching! :)

    Ok. Yes, I know what you mean. It would be nice to have more tutorials on how to build a full game.
    The problem here is likely that the service providers only know their own stuff really well. Meaning: We are no authority to show how to integrate PlayFab.
    Also, making games is quite individual. You will likely approach your next game in a different way and need another structure, too.

    So, for better or worse, game programming is learned in chunks per topic.
    I would possibly check video tutorials on YT on making a full game. Maybe some streamer has a full example and more hints?

    > I wanted people to create "rooms" which stay active for however long the game lasts

    In theory, you could make Photon send your game state to a server you provide to store it. When the players want to open it again, Photon will fetch it.
    This opens the option to have multiple rooms per player (entering one by one) but there is no ready-made server to store game states and list them per user.
    I would recommend finishing a game first, before entering that rabbit hole, however.

    > And indeed play people globally

    Just pick any of the regions we offer and set this as only option in the Region Whitelist for your app. Everyone will use that region and you got global games.

    > if you guys would build a tutorial system around your software that deals with this structure and architecture, it would be the smart thing to do for your business

    Well. The comparison to Adobe and whatnot is not fitting here. The equivalent of your request to us, would be to ask them to make tutorials which explain how to use Windows, Mac and Linux to make their software run and how to market the images properly.

    But you are sure right that more learning material is always better.
    We definitely try to make things easy but we have to watch the scope.

    > Everyone can use a smart phone without having to use a manual

    I have to disagree. Everyone can look at it and make it show a random screen. But give it to someone who never saw you use it and having no buttons is a real show stopper. I've seen plenty of calls going unanswered, because the person didn't know where to swipe in which direction, when it actually rings.

  • I meant Pitching In ...not pitching ;)

    And I am not requesting as such, ... it's more or less an observation that if you make something easy to do , people will flock to it.

    And people who don't know how to operate a mobile phone ... well that's Darwinism at work I am afraid :)

    As to me storing a gamestate on a remote server , that is indeed not what I am going to be doing in the foreseeable future ... if I can get my turn iterator to work and scoring to persist on the network between rounds I am not going to touch the code anymore and if by some stroke of luck the game becomes successful enough I'll probably hire someone to do all of the networking stuff in the future , as it has been quite aggravating just getting it to work

  • I guess I also meant pitching in. English is not my first language :)
    I'll probably hire someone to do all of the networking stuff in the future

    Hehe. It can get pretty annoying, I guess.
    Best of luck creating jobs with the game!!