Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Comparing client and master client arrays with Photon

Discussion in 'Scripting' started by bfulcher, Nov 18, 2020.

  1. bfulcher

    bfulcher

    Joined:
    Oct 7, 2019
    Posts:
    3
    So I'm really new to networking and coding, and I've run into a wall. I'm trying to figure out what the best approach is for doing what I want and I would love some input.

    In each Photon Room I have 2 or more players. Each player has the same set of dominoes, and slots where the dominoes can be placed. The players will place these dominoes independent of each other with the goal being to match placement and z-rotation of each domino to the master client's identical domino. This is where I'm stuck.

    I'm trying to understand how to compare local player's domino A to master client's domino A, and do this for each domino in play. For each domino that matches rotation and parent, I want to add to a score counter and display this score on a separate scene.

    As of now, I can print the local parent and rotation value for each domino, but I don't know how to compare them to the master client. I'm able to print this using a foreach loop, but haven't created an array or list. I've been looking into using RPCs and it seems like the right direction, but I'm not really sure how to approach it. I've also considered custom properties for the Room or for each player, but again, I'm not sure how to structure or execute this.

    I'm happy to post any code that I have for better understanding of the project, but I'm just lost at the moment and would lovesome feedback on the best approach for something like this. Any help is appreciated, and thanks in advanced!
     
  2. VishwasGagrani

    VishwasGagrani

    Joined:
    May 12, 2018
    Posts:
    81
    When a client joins a server. The server calls back onRoomJoin ( or something similar) event for the client side. This callback's event parameter can be used to get the id of the player. This id needs to be saved to each client.
    So for example, server has got 5 players joined in. With id 1,2,3,4,5 . Then each client will save it's own id. Client-1 will save 1, client 2 will save 2 etc.

    To assign the ids to each of the 5 actors you can send an array of all ids from the server to each client.

    However if the number of players is larger then this may take a lot of bandwidth. In that case you can create an array on client side. And update it on every server callback for onNewPlayerJoinedRoom. You may need to numerically sort the array because you cannot rely the server will call this function in the same sequence on each client.

    PS: If the player ids generated are alphabetic or alphanumeric you will need to choose the sort accordingly. The main aim of sorting here is to get the same sequence of ids on each client because we cannot rely the server callback has occured in same sequence on each client.