Change Value .

1- Let say I have a variable X .
I want every player enter the room Compare his “X” Value with my X Value .
2- can I change his X Value

Maybe a small example .

Yes you can.
Please show us what you tried.

Also, please do not duplicate posts. Thx.

Simple thing
I want every player enter the room
1- get from him the value of X
2- change him the value of X

It depends to some degree on which networking solution you’re using.

In Photon PUN, you’d probably want use a CustomPlayerProperty and in UNET a Syncvar (but I wouldn’t recommend using UNET anyway, as it’s deprecated.) Other networking solutions may have different approaches.

You didn’t do what Antypodish asked, you just repeated your first question in a slightly different word order. Without giving us more to go on you’re unlikely to get anything more specific in the way of advice.

1 Like

i am using PUN2 .

in a case that i have create a room and entered the room … and i have a Variable X for each player … i want to change for every player enter room the value of X .
how i cant do that ?

As I said in my previous reply, a CustomPlayerProperty sounds like it may be what you need.

If you don’t know what that is you should probably work through a few tutorials from the Exit Games website. It’s impossible to give you any further advice from the scant information you’ve provided.

Ok thank you I’ll try it .

I am using Pun2
Let say that there is twi variables int X and boll passing . A player was joined the room I want to compare if the value if his X= the value of my X . If yes pass a true to his boolian variable
That’s it .

Implement IInRoomCallbacks and then do something like

    public void OnPlayerEnteredRoom(Player newPlayer)
    {
        if (((int)newPlayer.CustomProperties["key"]) == ((int)PhotonNetwork.LocalPlayer.CustomProperties["key"]))
        {
            // Do your thing here...
            // The easiest thing is probably to call an RPC on the newPlayer object that sets the value of his bool.
        }
    }

This tutorial has an example of how to set up a custom property https://sharpcoderblog.com/blog/photon-network-beginners-guide

i do it but now i have a problem calling the RPC … sorry i am new on PUN .how can i call the newPlayer to create a Button for example.

Can you Please ?

You say you have a problem calling the RPC, but you don’t say what the problem is, and more importantly you haven’t posted your code.

If you post the code that you’ve tried that doesn’t work, then we can have a look at that and help you correct it.

1 Like

OK … Sorry
my mission is to create a room remotly for a client that i spacify the name and the size and the password … and store them on the [Key] … i create a temperolaly room and the client automacly enter the room … checking his confirm code if its ok then i can pass for him the keys (Variables) and add to the listvew an item of the room … he can then enter the room by choosing that item …
a script was like that but all the time i had errors and some times no errors but didnt add any item to his listview ("i want to add the item to him not to me . also if it add for him and me its ok)
one of the mostly errors was : PhotonView with ID 1001 has no method …

My Script:

using System.Collections.Generic;
using ExitGames.Client.Photon;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.UI;

public class Add_Room : MonoBehaviourPunCallbacks
{

    public GameObject Prefab;
    public Transform trans;

    public InputField Room_Name;
    public InputField Room_Size;
    public InputField Room_Password;
    public InputField Room_Coast;
    public InputField Room_Confirm_Code;
    public InputField Room_Master_Confirm_Code;
    Text[] txt;
    public GameObject Start_Screen;
    public GameObject Room_Screen;
    public GameObject Room_Setup;
  
    bool Create_Room_Is_OK = false;
   // Load_Rooms LD = new Load_Rooms();
    public static GameObject parents;
    public GameObject source;
     PhotonView pv;
    public Player My_New_Player;
    Hashtable setPlayerProperties;
    //public override void OnEnable()
    //{
    //    Debug.Log("Scene Enabled");
    //    if(!PhotonNetwork.InLobby)
    //       PhotonNetwork.JoinLobby(TypedLobby.Default);
    //}
    private void Start()
    {      
        //if (Load_Rooms.Player_Name != "tamim")
        if (!PhotonNetwork.InRoom)
            PhotonNetwork.JoinLobby(TypedLobby.Default);

    }
  
    //public override void OnRoomListUpdate(List<RoomInfo> roomList)
    //{
    //    Debug.Log("room Name: " + ++xxx);
    //    Debug.Log("room List: " + roomList.Count);
    //    if (Load_Rooms.ClientConfirmCode != "" && Load_Rooms.Player_Name != "tamim")
    //        PhotonNetwork.JoinRoom("RG5", null);
    //}
    public override void OnJoinedLobby()
    {
        if (Load_Rooms.ClientConfirmCode != "" && Load_Rooms.Player_Name != "tamim")
        {
            PhotonNetwork.JoinRoom("RG5", null);
        }
            //Set our Player's property
            setPlayerProperties = new Hashtable();
            setPlayerProperties.Add("PlayerCC", (string)Load_Rooms.ClientConfirmCode);
            setPlayerProperties.Add("PlayerRN", (string)Load_Rooms.ClientRoomName);
            setPlayerProperties.Add("PlayerRS", (int)Load_Rooms.ClientRoomSize);
            setPlayerProperties.Add("PlayerRP", (string)Load_Rooms.ClintRoomPassword);
        PhotonNetwork.LocalPlayer.SetCustomProperties(setPlayerProperties);
      
        ////Will print "100"
        //print((string)PhotonNetwork.LocalPlayer.CustomProperties["PlayerHP"]);
        //Debug.Log("0-State is: " + PhotonNetwork.NetworkClientState.ToString());


    }
    public void Adding_Room()
    {
        if (PhotonNetwork.InRoom) return;
            if (Room_Name.text!="" && Room_Size.text!="" && Room_Password.text!="" && Room_Confirm_Code.text!="" && Room_Coast.text!="" && Room_Master_Confirm_Code.text=="")
        {          
            if (check_if_Room_name_Not_Present(Room_Name.text) == false)
            {
                GameObject go = (GameObject)Instantiate(Prefab);
                go.transform.SetParent(trans, false);
                txt = go.GetComponentsInChildren<Text>();
                txt[0].text = Room_Name.text;
                txt[1].text = "0/" + Room_Size.text;

                Debug.Log(txt[0].text);
                Debug.Log(txt[1].text);

                //RoomInfo rmf;
                _RoomsList rm = new _RoomsList();
                rm.RoomName = Room_Name.text;

                rm.RoomSize = int.Parse(Room_Size.text);
                rm.RoomPassword = Room_Password.text;
                rm.Room_Coast_Per_one = int.Parse(Room_Coast.text);
                rm.RoomConfirmCode = Room_Confirm_Code.text;
                //rm.Room_Is_Active = true;
                //rm.Room_Is_Private = false;
                //RoomOptions ro = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = (byte)int.Parse(Room_Size.text) };
                //PhotonNetwork.CreateRoom(Room_Name.text, ro, TypedLobby.Default, null);
                Debug.Log("had creat a room with name: " + Room_Name.text);
                First_Connection.MC.Rooms.Add(rm);
                // First_Connection.MC.rooms
                First_Connection.Save();
            }
        }
      if (Room_Name.text != "" && Room_Size.text != "" && Room_Password.text != "" && Room_Confirm_Code.text != "" && Room_Coast.text != "" && Room_Master_Confirm_Code.text != "")
        {
          
            Load_Rooms.ClientRoomName = Room_Name.text;
            Load_Rooms.ClientRoomSize = int.Parse(Room_Size.text);
            Load_Rooms.ClintRoomPassword = Room_Password.text;
            Load_Rooms.ClientRoomCoast = int.Parse(Room_Coast.text);
            Load_Rooms.ClientConfirmCode = Room_Confirm_Code.text;
            Load_Rooms.MasterConfirmCode = Room_Master_Confirm_Code.text;

            setPlayerProperties.Clear();
            setPlayerProperties.Add("PlayerCC", (string)Load_Rooms.ClientConfirmCode);
            setPlayerProperties.Add("PlayerRN", (string)Load_Rooms.ClientRoomName);
            setPlayerProperties.Add("PlayerRS", (int)Load_Rooms.ClientRoomSize);
            setPlayerProperties.Add("PlayerRP", (string)Load_Rooms.ClintRoomPassword);
            PhotonNetwork.LocalPlayer.SetCustomProperties(setPlayerProperties);
            //if (PhotonNetwork.InLobby)
            {              
                Go_To_Rooms_Screen();
                RoomOptions ro = new RoomOptions() { IsVisible = true, IsOpen = true,MaxPlayers = 4 };
                PhotonNetwork.JoinOrCreateRoom("RG5",ro,TypedLobby.Default,null);  
                          
            }
        }
    }
  
    public override void OnJoinedRoom()
    {      
        Debug.Log("My Confirm Code is: " + (string)PhotonNetwork.LocalPlayer.CustomProperties["PlayerCC"]);
        Debug.Log("4-State is: " + PhotonNetwork.NetworkClientState.ToString());
        parents = PhotonNetwork.Instantiate("My_View", new Vector3(0, 0.5f, 0), Quaternion.identity, 0);
        parents.transform.SetParent(source.transform);
        pv = parents.GetComponent<PhotonView>();
        pv.RPC("Create_Room", RpcTarget.AllBuffered,(string) PhotonNetwork.LocalPlayer.CustomProperties["PlayerRN"],(int) PhotonNetwork.LocalPlayer.CustomProperties["PlayerRS"],(string)PhotonNetwork.LocalPlayer.CustomProperties["PlayerRP"]);
    }
    [PunRPC]
   public void Create_Room(string rn, int rs, string rp)
    {
        Debug.Log("Creating List Object Room For: " + My_New_Player.NickName);
        GameObject go = (GameObject)Instantiate(Prefab);
        go.transform.SetParent(trans, false);
        txt = go.GetComponentsInChildren<Text>();
        txt[0].text = rn;
        txt[1].text = "0/" + rs.ToString();

    }
    public override void OnPlayerEnteredRoom (Player newPlayer)
    {
      
        print((string)PhotonNetwork.LocalPlayer.CustomProperties["PlayerCC"]);
        print((string)newPlayer.CustomProperties["PlayerCC"]);
        if(PhotonNetwork.PlayerList.Length==1) PhotonNetwork.SetMasterClient(newPlayer);                  

        if (((string)newPlayer.CustomProperties["PlayerCC"]) == ((string)PhotonNetwork.LocalPlayer.CustomProperties["PlayerCC"])&& PhotonNetwork.PlayerList.Length>1)
        {          
            Debug.Log("Player Entered The Room: " + newPlayer.NickName);
            Create_Room_Is_OK = true;
            //My_New_Player = newPlayer;
             // PhotonNetwork.LeaveRoom();
            // The easiest thing is probably to call an RPC on the newPlayer object that sets the value of his bool.
        }
    }
  
    public override void OnLeftRoom()
    {
        if(Create_Room_Is_OK==true)
        {
            if (check_if_Room_name_Not_Present(Room_Name.text) == false)
            {
                GameObject go = (GameObject)Instantiate(Prefab);
                go.transform.SetParent(trans, false);
                txt = go.GetComponentsInChildren<Text>();
                txt[0].text = Load_Rooms.ClientRoomName;
                txt[1].text = "0/" + Load_Rooms.ClientRoomSize.ToString();

                Debug.Log(txt[0].text);
                Debug.Log(txt[1].text);

                //RoomInfo rmf;
                _RoomsList rm = new _RoomsList();
                rm.RoomName = Load_Rooms.ClientRoomName;

                rm.RoomSize = int.Parse(Load_Rooms.ClientRoomSize.ToString());
                rm.RoomPassword = Load_Rooms.ClintRoomPassword;
                rm.Room_Coast_Per_one = (Load_Rooms.ClientRoomCoast);
                rm.RoomConfirmCode = Load_Rooms.ClientConfirmCode;
                //rm.Room_Is_Active = true;
                //rm.Room_Is_Private = false;
                //RoomOptions ro = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = (byte)int.Parse(Room_Size.text) };
                //PhotonNetwork.CreateRoom(Room_Name.text, ro, TypedLobby.Default, null);
                Debug.Log("had creat a room with name: " + Room_Name.text);
                First_Connection.MC.Rooms.Add(rm);
                // First_Connection.MC.rooms
                First_Connection.Save();
            }
        }
        Go_To_Rooms_Screen();
    }
    bool check_if_Room_name_Not_Present(string name)
    {
        if (First_Connection.MC.Rooms == null) return false;
        for (int i = 0; i < First_Connection.MC.Rooms.Count; i++)
        {
            if (First_Connection.MC.Rooms[I].RoomName == name)
            {
                First_Connection.MC.Rooms[I].RoomName = Room_Name.text;
                First_Connection.MC.Rooms[I].RoomSize = int.Parse(Room_Size.text);
                First_Connection.MC.Rooms[I].RoomPassword = Room_Password.text;
                First_Connection.MC.Rooms[I].RoomConfirmCode = Room_Confirm_Code.text;
                First_Connection.MC.Rooms[I].Room_Coast_Per_one = int.Parse(Room_Coast.text);

                //First_Connection.MC.Rooms[I].Room_Is_Active = true;
                //First_Connection.MC.Rooms[I].Room_Is_Private = false;
                First_Connection.Save();
                Go_To_Rooms_Screen();
                return true;
            }
        }
        return false;
    }

    public void Go_To_Rooms_Screen()
    {
        Start_Screen.SetActive(false);
        Room_Screen.SetActive(true);
        Room_Setup.SetActive(false);
    }
}

[/I][/I][/I][/I][/I][/I][/I][/I]

@Livindaki
To make code easier to read, you can use Code Tags (you can edit post).
** Using code tags properly **
This will allow us easier to follow your script and also adds lines numbers.

1 Like