Set GLOBAL to SFSRoomVariable

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

Post Reply
ggirginov
Posts: 7
Joined: 27 Apr 2012, 15:39

Set GLOBAL to SFSRoomVariable

Post by ggirginov »

Hi,
I have problem. I can not set global property to SFSRoomVariable.
I try to do this with:
1/ parameter ....: new SFSRoomVariable("name", 0, true, false, true)
2/ set method ...: createdVar.setGlobal(true);

but i can't.

Please support me.
Best regards, Georgi.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Set GLOBAL to SFSRoomVariable

Post by rjgtav »

Hello.
Well, I assume you are running that code on the server-side, correct? Because you can't create global variables from the client-side.
Is there any error thrown on the console? What isn't working?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
ggirginov
Posts: 7
Joined: 27 Apr 2012, 15:39

Re: Set GLOBAL to SFSRoomVariable

Post by ggirginov »

Hello,
Thanks for the answer.
Yes, of course... I am running it on server's side. I do not have a console error, but my client hasn't received the variables which the server sent. The client receives only empty array (null). I attach a screenshot at my zone monitorring
Attachments
n.jpg
(28.61 KiB) Not downloaded yet
itsmylifesoham
Posts: 186
Joined: 16 Oct 2011, 14:33

Re: Set GLOBAL to SFSRoomVariable

Post by itsmylifesoham »

when you set a room variable on the room object serverside as "global" , the client will not be sent anything .

but when this global variable will change, a ROOM_VARIABLE_UPDATE event will be fired to the clients who are inside the room,as well as to the clients who are only subscribed to the groupid of the particular room.

please post some sample code about what you want to notify to the client exactly and what are you expecting should happen when you call setGlobal() serverside.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Set GLOBAL to SFSRoomVariable

Post by rjgtav »

Please make sure that you're setting the variable via SFSApi.setRoomVariables() method.
Could you post the code that you're using for setting a global variable?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
ggirginov
Posts: 7
Joined: 27 Apr 2012, 15:39

Re: Set GLOBAL to SFSRoomVariable

Post by ggirginov »

1/ Get current room and create ArrayList:
Room thisRoom = user.getLastJoinedRoom();
ArrayList<RoomVariable> rVars = new ArrayList<RoomVariable>();

2/ I'm trying to create global variable like this:
rVars.add(new SFSRoomVariable("gtimeout", gtimeout, true, false, true));

3/ And I'm trying to create global variable like this:
SFSRoomVariable temp = new SFSRoomVariable("upto", upto);
temp.setGlobal(true);

4/ And I set room variables like this:
this.getParentExtension().getApi().setRoomVariables(null, thisRoom, rVars);

5/ Finaly:
send(Protocol.CMD_D_VARS, null, user);
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Set GLOBAL to SFSRoomVariable

Post by rjgtav »

Well, I just tested a similar code and it worked flawlessly (note: usually you set the variables when you create the room, not after you create it):

Code: Select all

//Creates the Room
CreateRoomSettings roomSettings = new CreateRoomSettings();
roomSettings.setName("TestRoom");
Room room = getApi().createRoom(TestExtension.Zone, roomSettings, null);
//Sets the variable
ArrayList<RoomVariable> rVars = new ArrayList<RoomVariable>();
rVars.add(new SFSRoomVariable("test", 1, true, false, true));
getApi().setRoomVariables(null, room, rVars);
Please make sure that you're using the latest SFS2X Final Release (2.0.1).
Are you sure that you haven't set that variable before from the client and set it to private? If so, then the variable can't be changed from the server, unless you set true as the overrideOwnership param of the SFSApi.setRoomVariables() method.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
ggirginov
Posts: 7
Joined: 27 Apr 2012, 15:39

Re: Set GLOBAL to SFSRoomVariable

Post by ggirginov »

Thanks for your help
My solution is:

1/ Get current room and create ArrayList:
Room thisRoom = user.getLastJoinedRoom();
ArrayList<RoomVariable> rVars = new ArrayList<RoomVariable>();

2/ I get the current values ​​of variables and set the value in new variable:
Integer myVariavle = (Integer)thisRoom.getvariable("myVar").getValue();

3/ Remove variable in current room
thisRoom.removeVariable("myVar");

4/ And I set room variables like this:
rVars.add(new SFSRoomVariable("myVar", myVariavle, true, false, true));
this.getParentExtension().getApi().setRoomVariables(null, thisRoom, rVars);
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Set GLOBAL to SFSRoomVariable

Post by rjgtav »

You don't need to remove the variable before setting it again.
What happens if you skip step 3?
Try using this.getParentExtension().getApi().setRoomVariables(null, thisRoom, rVars, true, true, true) instead
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
ggirginov
Posts: 7
Joined: 27 Apr 2012, 15:39

Re: Set GLOBAL to SFSRoomVariable

Post by ggirginov »

I tried to set global like in your example so many times, but it did not work! :(
If I skip step 3 the variable can not be set to global. :)
Best regards!
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Set GLOBAL to SFSRoomVariable

Post by rjgtav »

Weird... How do you set that variable for the first time?
And are you running the latest SFS2X 2.1.0 patch?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Post Reply