getApi().setRoomVariables OWNER

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

Moderators: Lapo, Bax

Ceciaman
Posts: 45
Joined: 13 Feb 2009, 11:35

getApi().setRoomVariables OWNER

Postby Ceciaman » 27 Apr 2021, 22:56

Hi Lapo,
i want that the variable was assign to user but olso if i write "sender" this variables was assigned always to server.
What can i do?


Code: Select all

function init(){
addRequestHandler("cv", cv);
----
----
}

function cv(params,sender){

var Pos=params.getUtfString("Pos");
var room=getParentZone().getRoomByName("Androne");
var P;
var A;
var Arrays;
  var resObj = new SFSObject();
  resObj.putUtfString("Pos",params.getUtfString("Pos"));

  if(Pos=="P1")
  {
  P =new SFSRoomVariable("P1",params.getUtfString("P"));
  A =new SFSRoomVariable("A1",params.getUtfString("A"));
  resObj.putUtfString("P1",params.getUtfString("P"));
  resObj.putUtfString("A1",params.getUtfString("A"));
  }

  if(Pos=="P2")
  {
  P =new SFSRoomVariable("P2",params.getUtfString("P"));
  A =new SFSRoomVariable("A2",params.getUtfString("A"));
  resObj.putUtfString("P2",params.getUtfString("P"));
  resObj.putUtfString("A2",params.getUtfString("A"));
  }

  if(Pos=="P3")
  {
  P =new SFSRoomVariable("P3",params.getUtfString("P"));
  A =new SFSRoomVariable("A3",params.getUtfString("A"));
  resObj.putUtfString("P3",params.getUtfString("P"));
  resObj.putUtfString("A3",params.getUtfString("A"));
  }

  if(Pos=="P4")
  {
  P =new SFSRoomVariable("P4",params.getUtfString("P"));
  A =new SFSRoomVariable("A4",params.getUtfString("A"));
  resObj.putUtfString("P4",params.getUtfString("P"));
  resObj.putUtfString("A4",params.getUtfString("A"));
  }

 P.setGlobal(true);
 A.setGlobal(true);

 Arrays=[P,A];

  getApi().setRoomVariables(sender, room, Arrays);
  send("cv", resObj, room.getUserList());
}
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: getApi().setRoomVariables OWNER

Postby Lapo » 28 Apr 2021, 07:02

Hi,
each RoomVariable has an owner property that can be accessed via the getOwner() and setOwner() methods.

In other words you can do this (from server side only):

Code: Select all

var roomVar1 = new SFSRoomVariable("posx", 100);
var roomVar2 = new SFSRoomVariable("posy", 200);

// change owner
roomVar1.setOwner(someUserObj);

// etc...

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
Ceciaman
Posts: 45
Joined: 13 Feb 2009, 11:35

Re: getApi().setRoomVariables OWNER

Postby Ceciaman » 28 Apr 2021, 08:13

Thanks Lapo, i've put only isGlobal....

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 75 guests