Coroutine and photonView.RPC

Options
Hi to everyone and sorry for my english.

I am new with Photon and I have a problem with Coroutine and photonView.RPC

I am trying to do this:

Inside a coroutine i use photonView.RPC.
(I searched on internet and everyone said that we cant use photonView.RPC inside a coroutine).

The game is TurnBased...

Some of my code is:

private bool g_player_select_card = false;

void Start()
{
if (PhotonNetwork.IsMasterClient)
{
.... some code ...
StartCoroutine(CR_f_Phase_Select_SC());
}
}

IEnumerator CR_f_Phase_Select_SC()
{
... some code...

//--- here is the data that i want to send to all clients...
string[] l_str_array = new string[3];
l_str_array[0] = gameround.ToString(); // gameround is local int.
l_str_array[1] = player_turn.ToString(); // player_turn is local int.
l_str_array[2] = player_name; // player_name is local string.

//--- i am trying to send them with photonView.RPC...
photonView.RPC("RPC_f_Get_The_State", RpcTarget.All, l_str_array);

// when the client receive the data... its show up 3 cards and the player must select 1.
// when the client press the button DONE it send message to MasterClient with all the information
// that he needs to proceed...
// and the MasterClient change the value of "g_player_select_card" to "true".

while (g_player_select_card == false)
{
yield return null;
}
}

[PunRPC]
private void RPC_f_Get_The_State(string[] l_str_arr)
{
int l_game_round = int.Parse(l_str_arr[0]);
int l_player_turn = int.Parse(l_str_arr[1]);
string l_player_name = l_str_arr[2];

... some code...

}

And here is my problem and my question...

1) I Build it and I run it on the same pc... MasterClient on Build ... Client on Unity.
2) When I run it and it goes to this section... it happens something strange for me...

If I run it as you see...
In first condition: When The MasterClient is selecting first and the Client second... : they run ok both of them...
in second condition: When The Client is selecting first and the MasterClient second:
--- the MasterClient is waiting for the Client (its ok)
--- on Client nothing happened... no cards showing... nothing at all...

and here the question and what I noticed and its surprise for me...

WHEN I PUT A : Debug.Log(l_player_name); before the ... some code... (as below)

[PunRPC]
private void RPC_f_Get_The_State(string[] l_str_arr)
{
int l_game_round = int.Parse(l_str_arr[0]);
int l_player_turn = int.Parse(l_str_arr[1]);
string l_player_name = l_str_arr[2];

Debug.Log(l_player_name);

... some code...

}

In Console its showing the player name as normal... and the Client works fine in any playing codition... as first pick or as second pick...

Why this happened ?

thank you for your patience and sorry for my english again...

And Happy New Year 2021...

Best regards
Jim

Comments

  • JimNew
    Options
    JimNew wrote: »
    Hi to everyone and sorry for my english.

    I am new with Photon and I have a problem with Coroutine and photonView.RPC

    I am trying to do this:

    Inside a coroutine i use photonView.RPC.
    (I searched on internet and everyone said that we cant use photonView.RPC inside a coroutine).

    The game is TurnBased...

    Some of my code is:

    private bool g_player_select_card = false;

    void Start()
    {
    if (PhotonNetwork.IsMasterClient)
    {
    .... some code ...
    StartCoroutine(CR_f_Phase_Select_SC());
    }
    }

    IEnumerator CR_f_Phase_Select_SC()
    {
    ... some code...

    //--- here is the data that i want to send to all clients...
    string[] l_str_array = new string[3];
    l_str_array[0] = gameround.ToString(); // gameround is local int.
    l_str_array[1] = player_turn.ToString(); // player_turn is local int.
    l_str_array[2] = player_name; // player_name is local string.

    //--- i am trying to send them with photonView.RPC...
    photonView.RPC("RPC_f_Get_The_State", RpcTarget.All, l_str_array);

    // when the client receive the data... its show up 3 cards and the player must select 1.
    // when the client press the button DONE it send message to MasterClient with all the information
    // that he needs to proceed...
    // and the MasterClient change the value of "g_player_select_card" to "true".

    while (g_player_select_card == false)
    {
    yield return null;
    }
    }

    [PunRPC]
    private void RPC_f_Get_The_State(string[] l_str_arr)
    {
    int l_game_round = int.Parse(l_str_arr[0]);
    int l_player_turn = int.Parse(l_str_arr[1]);
    string l_player_name = l_str_arr[2];

    ... some code...

    }

    And here is my problem and my question...

    1) I Build it and I run it on the same pc... MasterClient on Build ... Client on Unity.
    2) When I run it and it goes to this section... it happens something strange for me...

    If I run it as you see...
    In first condition: When The MasterClient is selecting first and the Client second... : they run ok both of them...
    in second condition: When The Client is selecting first and the MasterClient second:
    --- the MasterClient is waiting for the Client (its ok)
    --- on Client nothing happened... no cards showing... nothing at all...

    and here the question and what I noticed and its surprise for me...

    WHEN I PUT A : Debug.Log(l_player_name); before the ... some code... (as below)

    [PunRPC]
    private void RPC_f_Get_The_State(string[] l_str_arr)
    {
    int l_game_round = int.Parse(l_str_arr[0]);
    int l_player_turn = int.Parse(l_str_arr[1]);
    string l_player_name = l_str_arr[2];

    Debug.Log(l_player_name);

    ... some code...

    }

    In Console its showing the player name as normal... and the Client works fine in any playing codition... as first pick or as second pick...

    Why this happened ?

    thank you for your patience and sorry for my english again...

    And Happy New Year 2021...

    Best regards
    Jim

    Edit: Today i am trying to play and the problem continues...
    So the Degug.Log didnt solve the problem.
    Yesterday it worked fine. I didnt change anything from yesterday.
    Today : The problem is that the client takes the values normally... i see them in the console... but they doesnt showing up when i am using them in Unity. (sorry for my english)
  • JimNew
    Options
    JimNew wrote: »
    JimNew wrote: »
    Hi to everyone and sorry for my english.

    I am new with Photon and I have a problem with Coroutine and photonView.RPC

    I am trying to do this:

    Inside a coroutine i use photonView.RPC.
    (I searched on internet and everyone said that we cant use photonView.RPC inside a coroutine).

    The game is TurnBased...

    Some of my code is:

    private bool g_player_select_card = false;

    void Start()
    {
    if (PhotonNetwork.IsMasterClient)
    {
    .... some code ...
    StartCoroutine(CR_f_Phase_Select_SC());
    }
    }

    IEnumerator CR_f_Phase_Select_SC()
    {
    ... some code...

    //--- here is the data that i want to send to all clients...
    string[] l_str_array = new string[3];
    l_str_array[0] = gameround.ToString(); // gameround is local int.
    l_str_array[1] = player_turn.ToString(); // player_turn is local int.
    l_str_array[2] = player_name; // player_name is local string.

    //--- i am trying to send them with photonView.RPC...
    photonView.RPC("RPC_f_Get_The_State", RpcTarget.All, l_str_array);

    // when the client receive the data... its show up 3 cards and the player must select 1.
    // when the client press the button DONE it send message to MasterClient with all the information
    // that he needs to proceed...
    // and the MasterClient change the value of "g_player_select_card" to "true".

    while (g_player_select_card == false)
    {
    yield return null;
    }
    }

    [PunRPC]
    private void RPC_f_Get_The_State(string[] l_str_arr)
    {
    int l_game_round = int.Parse(l_str_arr[0]);
    int l_player_turn = int.Parse(l_str_arr[1]);
    string l_player_name = l_str_arr[2];

    ... some code...

    }

    And here is my problem and my question...

    1) I Build it and I run it on the same pc... MasterClient on Build ... Client on Unity.
    2) When I run it and it goes to this section... it happens something strange for me...

    If I run it as you see...
    In first condition: When The MasterClient is selecting first and the Client second... : they run ok both of them...
    in second condition: When The Client is selecting first and the MasterClient second:
    --- the MasterClient is waiting for the Client (its ok)
    --- on Client nothing happened... no cards showing... nothing at all...

    and here the question and what I noticed and its surprise for me...

    WHEN I PUT A : Debug.Log(l_player_name); before the ... some code... (as below)

    [PunRPC]
    private void RPC_f_Get_The_State(string[] l_str_arr)
    {
    int l_game_round = int.Parse(l_str_arr[0]);
    int l_player_turn = int.Parse(l_str_arr[1]);
    string l_player_name = l_str_arr[2];

    Debug.Log(l_player_name);

    ... some code...

    }

    In Console its showing the player name as normal... and the Client works fine in any playing codition... as first pick or as second pick...

    Why this happened ?

    thank you for your patience and sorry for my english again...

    And Happy New Year 2021...

    Best regards
    Jim

    Edit: Today i am trying to play and the problem continues...
    So the Degug.Log didnt solve the problem.
    Yesterday it worked fine. I didnt change anything from yesterday.
    Today : The problem is that the client takes the values normally... i see them in the console... but they doesnt showing up when i am using them in Unity. (sorry for my english)

    Edit 2:
    WOW... I tried something else...
    All the time I was trying to run it... the first from Build and the second on Unity.
    The MasterClient was on Build and the Client was on Unity. And the problem was there...

    When I try to run it from 2 Builds and not from Unity... the game plays normally.

    All the time that I am playing the Client from Build... the game is ok.
    For some reason ... when i am trying to play the Client from Unity... the game didnt play as normal.
    This problem showed to me again when I used the 2019.4.14f1...
    After the update to 2019.4.16f1 the problem solved...
    I did the last update 2019.4.17f1 on Monday 28-12-2020 and the problem is showing again...

    Maybe there is a bug to Unity when I run it ?

    sorry for my english and for so many info...

    Best Regards
    JimNew
  • JimNew
    Options
    Hi to all and sorry for my english.

    After some tests that I was trying I cant understand what is going on.

    My problem not solved and i dont know what to do.

    Some times works fine... some others its stucks...

    The problem is:

    I use photonView.RPC to send some values to all.
    All Clients and Server receives that values normally.
    After that a Canvas with these values ​​is displayed to the player in turn...

    In Server the Canvas allways is showing.
    In Clients sometimes is showing and sometimes not...(without change the code)... and thats the problem because he cant continues...

    There is no problem with Coroutine and photonView.RPC because the values are ok and send to all normally... i was trying this with Debug.Log everywhere and the values goes to clients...

    I dont know where is the problem... can u help me please ?
  • JimNew
    Options
    anyone ?
  • JimNew
    Options
    Hmmm, I found the problem... and it was my mistake...
    I had put the Canvas on a GameObject by mistake... and changed the enable to false sometimes...
    so.. Now I am OK.
  • Tobias
    Options
    Thanks for the update. Sorry we couldn't dive into this.
    Hope you're making good progress now.
This discussion has been closed.