playMaker

Author Topic: Photon and variables such as int  (Read 4603 times)

kanae

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
Photon and variables such as int
« on: October 18, 2014, 05:27:08 PM »
Hello,

How do I update variables such as int across all photon clients using an instantiated scene object?  I figured out how to get something like a boolean synced with RPC, but I'm a bit confused how to get other variables to sync.  When I just use "network sync" button the variables only update if it's the master client but not vice versa...  I understand players 'own' themselves, but what about objects that are owned by the scene...  It seems this should be easy but I can't make it happen?

I tried "room custom properties" but I don't think that's supposed to be used for variable syncing...  Since you can't even store variables using that action.

This has been driving me nuts for a few days, any help is appreciated
« Last Edit: October 19, 2014, 10:54:24 PM by kanae »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Re: Photon and variables such as int
« Reply #1 on: October 20, 2014, 12:03:16 AM »
Hi,

instantiated object belongs to the master client, and so you can synch variables, but  only the masterClient will be able to write values in these network variables.

 Otherwise you will have to use a regular network view on a gameobject. it's ok to have several gameobject with networkview for a given player, one can be the player character, and others can be scores, or abstract information about your game for that player ( maybe where it's looking, its weapons if complex, etc).

Bye,

 Jean

kanae

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
Re: Photon and variables such as int
« Reply #2 on: October 20, 2014, 12:26:40 AM »
thanks for the reply Jean!

but how do I tell the master client to update things like variables from other players?  If a player modifies a variable in the scene, I want to tell the master client to update that variable on the master client side so everyone sees the change, but how do I do that?

The only way I can see how to do it is RPC a string with the value (whether it's an INT, etc.)

There has to be a better way...  Maybe I'm missing something critical here but I can't seem to get variables to sync just using network view either, not even with the master client...  Argh!

This guy seemed to think Photon could only update the master client through RPC calls:  http://hutonggames.com/playmakerforum/index.php?topic=6596.msg32183#msg32183

But Jean also noted in another thread RPC calls use more bandwidth so it's better to use the normal network sync...  So I'm confused... which is it when using Photon...?
« Last Edit: October 20, 2014, 03:20:24 AM by kanae »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Re: Photon and variables such as int
« Reply #3 on: October 20, 2014, 03:40:59 AM »
Hi,

 no, it's actually the right way. the fact that you are failing to sync variables may be realted to something else tho.

 Can you try the sample provided? does that work, do you see your opponeng player moving and jumping properly? if that's the case then study carefully how it's all done. you know about the documentation on the wiki right?

https://hutonggames.fogbugz.com/?W928

 But maybe your design is wrong to begin with. Can you explain what you want to achieve in your game?

Bye,

 Jean

kanae

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
Re: Photon and variables such as int
« Reply #4 on: October 20, 2014, 03:56:21 AM »
I've looked through all the examples, including the standard play maker networking samples.  But still I need the master client remembering all the variables in case a player leaves so Photon can remember the variables.  My own game has no 'moving' actors, it's all variable-based.

But RPC calls are the only way to get master client variables to sync through Photon?

Right now I'm just trying to simply get variables to sync from the main scene.  I can get instantiated "players" working fine, but when it comes to sharing scene objects is when I run into trouble.  If I instantiate variables from a scene object I can get it working but with RPC calls which is a big process.

The problem is I have to rebuild the strings into variables (ints etc.)

If RPC calls are the only way to update master client variables from players, some prebuilt actions that do this would be really helpful...  Right now rebuilding RPC calls into actual variables is a pain in the butt, and makes the state machines a bit more complicated.  It seems like something an action could be doing.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Re: Photon and variables such as int
« Reply #5 on: October 20, 2014, 04:10:51 AM »
Hi,

 then the only way ( aside having a server) is to store this in the room custom properties and /or the player properties.

 It doesn't matter if you have moving parts, it's the same under the hood. if the demo works then variable synch works, it's up to your prefab to do what ever it wants with these synched variables.


when you instantiate a prefab, you don't need a masterclient to have it's variables persists, indeed, instantiated prefabs don't care about who's the masterclient, they synch from the owner of this prefab to the rest ( the owner being the instance on the computer that you called "Instantiate" from.

 I am still unsure about your use case, can you elaborate?

Bye,

 Jean

kanae

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
Re: Photon and variables such as int
« Reply #6 on: October 20, 2014, 08:07:05 PM »
Jean thanks for updating the Photon package!  I'm now trying to use the new instantiate scene object action, but still having trouble.

It's a problem because I want to use the same state machines whether it's online/offline mode, I don't think I can use Room Custom Properties or RPCs because you need to be connected to Photon

I'm instantiating "Test Manager" object which holds a bool variable, then when the gui button fsm is clicked (using a scene object) the bool is switched and a capsule appears.

Test Manager shows up on both clients after instantiation, but neither client is syncing.  The bool switch code seems to work fine, test manager object gets stored, passes the network bool variable to a global, then the global gets updated back into the network sync FSM.  But still they aren't syncing...  Argh!


(network sync is clicked here, the image just got cutoff)


(i didn't have a second client connected for this second picture)

There's another FSM that detects when the global is changed and does the logic, but it never touches the network sync bool
« Last Edit: October 20, 2014, 11:15:56 PM by kanae »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Re: Photon and variables such as int
« Reply #7 on: October 20, 2014, 11:25:45 PM »
Hi,

 Are you sure that you are writing if you are the masterClient? only the master client can write on this prefabs, the rest will be slaved.
 
and you don't have any errors in the console or warning, you may have forgot to add proxies on your prefab or something?

In my tests it was all fine, maybe you could share your prefab ( pm me) and I'll have a look.

Bye,

 Jean

kanae

  • Junior Playmaker
  • **
  • Posts: 52
    • View Profile
Re: Photon and variables such as int
« Reply #8 on: October 20, 2014, 11:56:08 PM »
Hey Jean,

I did finally get the Master client updating the instance, your comment about it made me realize I didn't have my second player getting the boolean every frame.  I've been looking at this one thing too much the last few days!!

So the only way to update the scene object with a non-master is through RPC calls?  So in order to update variables for offline mode I'll have to have separate "offline" and a "online" updates for variables...

At least with a scene object instantiated I can now use that for offline and for persistent online modes.  I'm happy to see when my Master Client leaves the instantiated scene object stays with the new master.  Thanks for that update!

I still think an action with RPCs variable options (int, vector etc) would be handier than trying to use Room Properties to manage variables, rebuilding RPC strings feels like an extra step.  Definitely this is complicated stuff I see why not a lot of people make multiplayer games.  I'm still happy to see Photon support here and look forward to continue building on this.

« Last Edit: October 20, 2014, 11:59:09 PM by kanae »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14059
  • Official Playmaker Support
    • View Profile
Re: Photon and variables such as int
« Reply #9 on: October 21, 2014, 12:55:17 AM »
Hi,

Yep, Networking is complex, but It seems you are getting into this very well!

RPC is not really the best approach to synch variables ( it is used under the hood for everything, but the implementation within PlayMaker is more for singular events).

 so, indeed the best way is to have a prefab that each player owns and so your masterclient will have this instance as slaved and you will be able to synch from player to the masterclient.

That's the best way.

Bye,

 Jean

600

  • Beta Group
  • Hero Member
  • *
  • Posts: 589
    • View Profile
    • Car and Traffic Playmaker assets
Re: Photon and variables such as int
« Reply #10 on: October 21, 2014, 02:24:14 AM »

So the only way to update the scene object with a non-master is through RPC calls?  So in order to update variables for offline mode I'll have to have separate "offline" and a "online" updates for variables...


Hi, I would like to add that you can use RPC in offline mode, they sends events like in multiplayer mode.
Same for Room custom properties, after this new update Offline mode is supported.