The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to handle return values RPC-style?

toreau
2014-04-27 03:48:23

I'm in the process of converting a proof of concept from singleplayer to multiplayer, using Photon Networking. I'm a bit puzzled on how to deal with RPCs and return values, or their lack of it, though.

Consider this singleplayer code:

[code2=csharp]if ( Input.GetKeyDown(KeyCode.H) && objectBeingLookedAt.isGatherable ) { RockResourceController resourceController = objectBeingLookedAt.transform.GetComponent<RockResourceController>(); inventoryController.AddItems ( resourceController.Hatchet () ); }

// Inside RockResourceController public Dictionary<Item, int> Hatchet () { Dictionary<Item, int> hatchedItems = new Dictionary<Item, int>();

}[/code2] How can/should I convert this logic into "multiplayer mode"? I've tried setting the Hatchet method to be an RPC, and I can of course call it, but how do I get its return value(s) back?

Thanks in advance!

UPDATE:

I came up with a solution. Well, "solution". :) It's something that works, but from my point of view it's less than beautiful;

[code2=csharp]if ( Input.GetKeyDown(KeyCode.H) && objectBeingLookedAt.isGatherable ) { RockResourceController resourceController = objectBeingLookedAt.transform.GetComponent<RockResourceController>(); resourceController.GetComponent<PhotonView>().RPC ( "Hatchet", PhotonTargets.All, inventoryController.photonView.viewID ); }

// Inside RockResourceController [RPC] public void Hatchet ( int playerInventoryPhotonViewId ) { Dictionary<Item, int> hatchedItems = new Dictionary<Item, int>();

}[/code2] Any suggestions on how to improve this workflow, if possible?

Thanks!

Comments

Tobias
2014-04-29 12:57:52

RPCs don't have a return value, because they could actually be running on any number of remote clients - including none at all. Which return code would you want? If you need some reaction, you will have to send another RPC to the origin of some RPC that needs a reply.

At the moment, I can't analyze your code. It's more effort to analyze what you DO versus what you MIGHT want to do. If you can describe what you need to do without posting code, it might help get a more directed reply.

Back to top