- Home /
Stream Send receive variable via photon cloud in js script
I search everywhere but could never find a working code in js script.
I need to send and receive a variable via photon cloud.
My photonnetwork is already in my Plugin folder..
Thanks for any tips !)
Are your imported package is in js or c#? Because as per my knowledge photon provide plugin in c# only.
In C#, I can help you in photon.
The Package is in C#. But as what i have read we can use this package and coding in js script also.. But nowhere i could find a working code in js.
Like most of time i must said the error is $$anonymous$$e...
$$anonymous$$y photonnetwork was in my plugin folder.. But so stupidly i forget that my js script is first in execution order...
So now i could have import Photon.$$anonymous$$onoBehaviour; with no error..
I suppose now i'm gonna find some working code !)
Now i'm trying this:
function OnPhotonSerializeView(stream : PhotonStream, info : Photon$$anonymous$$essageInfo )
{ Debug.Log ("photonserial");
if (stream.isWriting)
{stream.SendNext(test);
Debug.Log("send");}
else
{test = stream.ReceiveNext();
Debug.Log("receive");
}}
But none of the debuglog appear in the console... ;(
I would honestly advise just doing it in C#. There is literally almost no documentation for either C# or Unityscript, and the little documentation there is, is for C#.
Don't feel bad, I started with C# in Unity, then converted to Javascript because there were more tutorials on it. Then when I found Photon, it got me back into C# and now I can program better than I ever could.
Answer by Tepei · Oct 05, 2014 at 01:14 PM
I finaly get it !!! !)
So here's my way to do this : a: 1/ import photon cloud
2/ Drag the PhotonNetworks folder and the UtilityScript folder in the Plugins folder
3/ erase the Demos folder !
It will make a lot of error even if you don't use the script inside.. Erase and have a copy or find a folder where it stop to bug ... ... :)
(Another way could be to change the ProjectSetting/scriptcompilationorder to make the Js script compile after the C# script.)
b: Now to send and receive the variable your object must be the player you instantiate. If it's a common gameobject only the first player would send information.
c: Probably you have Drag the photonview script in your player game object then drag your player gameobject (transform) in the photonview script. To communicate move rotation..
Now drag again a photonview script to your player game object ! Now drag the js script component in the new photon view script !
d: here's the code :
function OnPhotonSerializeView(stream : PhotonStream, info : PhotonMessageInfo )
{ Debug.Log ("photonserial");
if(stream.isWriting){
stream.SendNext(GameMaster.test);
Debug.Log("send");
}
else{
GameMaster.test = stream.ReceiveNext();
Debug.Log("receive");
}
and it works !)
Yes it works .. But a use a static variable from a common object in the scene.. $$anonymous$$aybe this could cause bug.. Every player is gonna change this variable; but we don't know wich player have the last good value.. So a new player could reset it for all the other's... It works for a normal variable inside the player...
Your answer
![](https://koobas.hobune.stream/wayback/20220613164358im_/https://answers.unity.com/themes/thub/images/avi.jpg)