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

Problem while sending string via RPC with photon

Discussion in 'Scripting' started by wisien92, Feb 25, 2014.

  1. wisien92

    wisien92

    Joined:
    Nov 16, 2012
    Posts:
    56
    hi , i have this function that i want to send player's name:
    Code (csharp):
    1.  
    2. [RPC]
    3. public string getName() {
    4.       return playerName;
    5. }
    6.  
    and i want to recvie it by this where name is string:
    Code (csharp):
    1.  
    2. name = GetComponent<BetaMovement> ().photonView.RPC ("getName", PhotonTargets.AllBuffered);
    3.  
    it gives me error that i convert void to string .... so how do i use the rpc call to 'attach' this to name variable ?
     
  2. wisien92

    wisien92

    Joined:
    Nov 16, 2012
    Posts:
    56
    or maybe some other idea for getting info who killed who.

    i currently send the data to the bullet object that i create and send messa
     
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    photonView.RPC is void so you can't return things from it like that. Doesn't matter what the RPC'd method's signature is.
     
  4. wisien92

    wisien92

    Joined:
    Nov 16, 2012
    Posts:
    56
    so what's the solution to this problem ?
     
  5. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Um - don't try to assign the result of an RPC call to something...
     
  6. wisien92

    wisien92

    Joined:
    Nov 16, 2012
    Posts:
    56
    ok so i have method getName when i call it the problem is that 20 % times it doesnt work 80 % time it works .... have no idea why so i thought to call it as RPC becouse maybe everybody did not get this or something
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,018
    You can set each user's name via: PhotonNetwork.player.name.
    It's synced for you and you can have each user's name in PhotonNetwork.playerList.name.
     
  8. michealcaj

    michealcaj

    Joined:
    Aug 18, 2017
    Posts:
    191
    Yeeeeeeeeeeeeeeeeeehaaaaaaaaaaa

    Thanks brother you saved me a lot of stress