Need Help, Grabbing variable from other instances

Options
Kinda new to photon and need some help. So im making an rpg where you have 5 characters in your party. say you are fighting one enemy. My enemy has a function like this to pick his target:

public GameObject PickTarget()
{
if ( party1existsandisnotdead )
{
return party1;
}

else if ( party2existsandisnotdead )
{
return party2;
}

//and so on for all 5 party members

else return null;
}

works in single player, but i have a Co-Op mode now where 2 players use their party of 5 (10 total) against the enemy. I want the enemy to pick randomly from what client 1 returns (player 1 party) and what client 2 returns(player 2 party).

The variables used (party 1 through 5) are stored in a "Game Controller" script unique to each client, and i dont want to rebuild the list and sort it out because the logic of who gets targeted first is actually very complicated.

so basically i want to: run PickTarget() locally, RPC call PickTarget on other clients (which i know how to do), but then send back the RPC result and choose randomly between the result of both.

Answers

  • PhoenixRise
    Options
    of course i realize RPCs dont return anything which makes it harder.
  • Breeman
    Options
    Not 100% sure what you are asking, but can you use RPC to send another message back to MasterClient with the info you want to "return"?
  • PhoenixRise
    Options
    Right, like i need the RPC to send some info to the Master but im not sure if there is a short way to do it in photon code.
  • PhoenixRise
    Options
    or is there a way to reference a script on an object in instance 2(client) from instance 1(master). So i can just pull the variable off it?
  • Breeman
    Options
    I'm relatively new to Photon too, so someone else can chime in if what I'm saying is incorrect, but I believe what you are wanting to do is done by using RPC or serializing the data.

    Photon instantiates the objects as they join the room, but the only way to "see" their data is by using the methods they provide.
  • PhoenixRise
    Options
    i think my easiest choice is to make a new variable in that script to hold the result of the RPC which will sync across all clients, even though it is useless on the client where it runs
  • Breeman
    Options
    Yeah, you can just send with the RPC argument RpcTarget.Others so you don't have to worry about receiving it yourself.
  • PhoenixRise
    Options
    Ok, this might work. "PhotonMessageInfo" which can identify which object called the RPC

    // call code:
    photonView.RPC("ChatMessage", PhotonTargets.All, "jup", "and jup!");

    // the RPCs implementation:
    [PunRPC]
    void ChatMessage(string a, string b, PhotonMessageInfo info)
    {
    Debug.Log(String.Format("Info: {0} {1} {2}", info.sender, info.photonView, info.timestamp));
    }