Page 1 of 2
Room Variables from server
Posted: 25 Jan 2007, 01:32
by jaeta
I'm trying to update room variables from the server, but it does not appear to be working. I'm certainly getting a response back from the server after the client calls the extension, but the actual variables I have on the server never change. The variables are being set by the server initially in the server "config.xml" file. Anyone have any suggestions?
Many Thanks!
Code: Select all
<Zone name="multitest" customLogin="false" buddyList="20">
<Rooms>
<Room name="MainRoom" maxUsers="10" isPrivate="false"
isTemp="false" autoJoin="true">
<Vars>
<Var name="BlueScore" type="n" private="false">0</Var>
<Var name="RedScore" type="n" private="false">0</Var>
</Vars>
</Room>
</Rooms>
<Extensions>
<extension name="multitest" className="multitest.as" type="script"/>
</Extensions>
</Zone>
Code: Select all
function handleRequest(cmd, params, user, fromRoom) {
if (cmd == "scores") {
var room = _server.getCurrentRoom();
BlueScore = Number(params.values[0]);
RedScore = Number(params.values[1]);
vObj = new Array();
vObj.push({name:"BlueScore", val:BlueScore, priv:false});
vObj.push({name:"RedScore", val:RedScore, priv:false});
_server.setRoomVariables(room, null, vObj);
_server.sendResponse(params, -1, null, [user]);
}
}
[/code]
Posted: 25 Jan 2007, 11:54
by Lapo
Hi and welcome,
instead of this code:
Code: Select all
_server.setRoomVariables(room, null, vObj);
I'd use this:
Code: Select all
_server.setRoomVariables(room, user, vObj);
Let me know if it works
Posted: 25 Jan 2007, 14:06
by jaeta
Won't this kill the room variable when a user leaves the room? I want this game to be ongoing regardless of the number of players in the game. The score variable should stay on the server until the score either reaches a determined value or everyone leaves the game.
Posted: 25 Jan 2007, 15:59
by jaeta
I tried using the code you provided, but it's still not updating the room variables on the server.
Posted: 25 Jan 2007, 16:13
by Lapo
A couple of questions:
Are you checking if the variables are changed from the admin tool? (refresh the view after you have updated the variables)
What server version do you use?
Posted: 25 Jan 2007, 16:18
by jaeta
I am refreshing the admin tool and it still shows the score as being 0,0 even though I'm passing values of 10,10
Code: Select all
extensionName="multitest"
var obj:Object = {};
obj.values = [10, 10];
smartfox.sendXtMessage(extensionName, "scores", obj, "xml");
Using version 1.5.0
Posted: 25 Jan 2007, 16:21
by Lapo
do you get any errors from the server, after you have sent the extension request?
Posted: 25 Jan 2007, 16:25
by jaeta
Nope... this is what I get back from the server:
[multitest.as]: Bye bye!
[multitest.as]: Hello from the Simple Extension Example!
[multitest.as]: Event received: userJoin
[multitest.as]: RedScore=10
[multitest.as]: BlueScore=10
This is the extension script:
Code: Select all
function handleRequest(cmd, params, user, fromRoom) {
if (cmd == "scores") {
var room = _server.getCurrentRoom();
BlueScore = Number(params.values[0]);
RedScore = Number(params.values[1]);
trace("RedScore="+RedScore);
trace("BlueScore="+BlueScore);
vObj = new Array();
vObj.push({name:"BlueScore", val:BlueScore, priv:false});
vObj.push({name:"RedScore", val:RedScore, priv:false});
_server.setRoomVariables(room, user, vObj);
var response = {};
response._cmd = "scores";
response.values = [];
for (var i = 0; i<params.values.length; i++) {
var n = params.values[i];
response.values[i] = n;
}
_server.sendResponse(response, -1, null, [user]);
}
}
Posted: 25 Jan 2007, 18:12
by Lapo
I wasn't able to reproduce the problem. We tested a similar scenario and it worked.
Advice: make sure that this line of code
Code: Select all
var room = _server.getCurrentRoom();
is not returning
null
If your extension is at
Zone Level you should get a null, which in turn will make the setRoomVariables fail
Posted: 25 Jan 2007, 19:22
by jaeta
You were correct. It was returning a null. Upon moving the extension to the room level it started working.
Thanks!
Posted: 27 Mar 2007, 14:40
by melojoy
Hi,
I have to set room variables from the extension...
Code: Select all
// impostiamo le room variables
var room = _server.getCurrentRoom();
trace("La stanza è: "+room);
trace("Utente: "+user.name);
trace("Posizione: "+params.posizione);
var rVars = new Array();
rVars.push( {name:"g"+params.posizione, val:user.name, persistent:false} );
//_server.setRoomVariables(room, null, rVars);
_server.setRoomVariables(room, user, rVars);
trace("Variabile inserita: "+rVars[0].g0) //
This it doesn't work (also with null user) and the result is:
Code: Select all
[3-Sette4.as]: La stanza è: it.gotoandplay.smartfoxserver.data.Room@aa82b
[3-Sette4.as]: Utente: al
[3-Sette4.as]: Posizione: 0
[3-Sette4.as]: Variabile inserita: undefined
This code is in a room extension dynamically creates when I create a new game room
In the last trace if I put...
Code: Select all
trace("Variabile inserita: "+rVars[0]);
or
Code: Select all
trace("Variabile inserita: "+rVars);
... the result is
Code: Select all
[3-Sette4.as]: Variabile inserita: [object Object]
thanks

Posted: 28 Mar 2007, 10:14
by Lapo
it's a bit confusing!
params.posizione = undefined
Code: Select all
[3-Sette4.as]: Variabile inserita: undefined
but you use that variable to set a Room Var and you expect "g0"... but it will be "gundefined"
makes sense?
where is params.posizione coming from?
Posted: 30 Mar 2007, 08:00
by melojoy
Escuse me... this is mistaken
Code: Select all
trace("Variabile inserita: "+rVars[0].g0)
The correct trace is...
Code: Select all
trace("Variabile inserita: "+rVars[0].name)
trace("Variabile inserita: "+rVars[0].val)
This return the name and the value of the variable... but with the admin tool I don't see var in the room.
Thanks!
Posted: 03 Apr 2007, 08:00
by Lapo
Which version of the server do you use?
There was a bug with variable creation (when creating a room) in the first release of the 1.5.0 which was fixed with a later patch.
Posted: 29 Aug 2007, 05:41
by darnpunk
Hi Lapo,
I am not able to setRoomVariables from a different room. This is how I do it:
var rVars:Array = []
rVars.push( {name:"msg", val:"Sticky Test", persistent:false} )
smartfox.setRoomVariables(rVars, 4); // 4 is the roomId i am trying to set the variables to and i am in room id 3
I can only setRoomVariables successfully if I am in the same room. I am using SFS 1.5.5. Am I doing anything wrong?
Regards,
darnpunk