Execute server data on multiple clients

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

claudiu.m
Posts: 23
Joined: 10 Sep 2013, 08:51
Location: Germany

Execute server data on multiple clients

Postby claudiu.m » 21 Oct 2013, 09:28

Hello,
I have a dice game where on both client sides should execute the same code.
For example this function:

Code: Select all



 this.sfs.send(new SFS2X.Requests.System.ExtensionRequest(DICE_GAME.GAME_COMMANDS.GET_MYRAND_NR));
this.myRandF   = function(evt)
        {
            /**GET DATA VOM SERVER **/
             var first = evt.params.myRand[0];
             var sec = evt.params.myRand[1];
             var third = evt.params.myRand[2];
             var value = Math.floor(Math.random()* this.cubes1to20_arr.length);
             var cube = this.cubes1to20_arr[value];
             var if6 = cube.image.value;
         

         

            /** SETTING POSTIONS FOR THE CUBE **/
            var x = selbst.WB.x + selbst.WB.image.width;
            var y = selbst.WB.y + selbst.WB.image.height/2;
            //selbst.cubeToDelete = cube;

            /**CREATING TWEEN MOTION FOR MYRAND **/
            createjs.Tween.get(this.myrand).to({x:first},500).to({x:sec},500).to({x:third},500).to({x:cube.x},500);
            var myTween = createjs.Tween.get(cube).wait(2600).to({scaleX:0,scaleY:0,alpha:0},300, createjs.Ease.bounceOut).call(this.if_ready,[if6]);
            myTween.wait(200).set({alpha:1,x:x,y:y,scaleX:1,scaleY:1},cube);


        };


        this.sfs.addEventListener(SFS2X.SFSEvent.EXTENSION_RESPONSE,this.myRandF,this);



The tween motion is executed in the event listener's function so it should be seen by both of the clients but this only works on for one client.
How can I get this to be executed for both of the clients? My ideea was to call this motion function in the event listener' s function but if I am wrong what are other possibilities ?

Thank you in advance for your help
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Execute server data on multiple clients

Postby Lapo » 21 Oct 2013, 13:46

If the server response arrives to both clients, the animation code will be triggered on both clients as well.
... Unless I am missing something else...
Lapo
--
gotoAndPlay()
...addicted to flash games
claudiu.m
Posts: 23
Joined: 10 Sep 2013, 08:51
Location: Germany

Re: Execute server data on multiple clients

Postby claudiu.m » 21 Oct 2013, 15:31

Hi Lapo, yes you are right this is the way to do it.
my problem was that the command I got from the server was "undefined" for the second client so that is why it did not work for me.

Thank you again for replying :)

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Stevenor and 90 guests