Page 2 of 2
Posted: 13 May 2006, 21:37
by proschigom
i have been having the same problem from a very long time and have spent days n days over this. in my case, i can see my room variable (its just one variable) from the admin, when someone creates the room, i even recieve the variable in the xml like this:
Code: Select all
[Received]: <msg t="sys"><body action="roomAdd" r="0"><rm id="9" priv="0" temp="1" game="1" max="8" spec="1"><name>TESTING</name><vars><var n="minbet" t="n">1</var></vars></rm></body></msg>
but when i try to use: var xMinBet = room.getVariable("minbet"); at roomAdded or updateRoomStatus, it returns undefined all the time. Now this variable was assigned when the room was created, through the roomObj.vars = variables
I do remember once in another case, that i set the room variable after joining that room, i think i recieved the value in that scenario (i think)
So how have i been able to go ahead with this problem? .... im using the maxSpectator property instead, the value is aaaalways available and much more reliable, but absolutely not a permanant solution. Any help from anyone in this area would be awsome
Posted: 15 May 2006, 21:17
by alikapadia
ya there was a problem in the SmartfoxClient class in the it folder,
search for: 'if (action == "roomAdd")' over there was a line that said:
var variables = xmlObj.vars.vars
just changed that to 'var variables = xmlObj.rm.vars.vars'
rest works like a beauty
im not sure where this problem came from tho
Posted: 16 May 2006, 06:46
by Lapo
Sorry for the delay in responding, but I wanted to check the problem described by proschigom.
It seems that you're using a wrong version of the client API, as we were unable to reproduce the problem you told us about.
NOTE: I assume you're using the latest SmartFoxServer 1.4.0 (Basic or PRO)
To make sure you're using the latest API, just use this code:
It should say
1.0.2
If not you're using an old API version.
I've tested the problem you described by simply modifying the "Advanced Chat" example so that it creates a new room variable in each new room created.
Then I've added a trace in the onRoomAdded handler to dump all the room variables attached to the new room just received.
If you want I can provide the FLA of the test.
Hope it helps
to alikapadia
Posted: 16 May 2006, 06:48
by Lapo
to alikapadia:
ya there was a problem in the SmartfoxClient class in the it folder,
search for: 'if (action == "roomAdd")' over there was a line that said:
var variables = xmlObj.vars.vars
just changed that to 'var variables = xmlObj.rm.vars.vars'
rest works like a beauty
The problem doesn't exist in the latest API coming with SmartFoxServer 1.4.0. Are you sure you're using the latestet API?
You can check the version by using the example I provided in my previous post to proschigom
Posted: 16 May 2006, 10:33
by monkeypuzzle
Hi,
I'm having exactly the same problem too. I'm using SmartfoxServer 1.4.0 Basic, I used the getVersion to check the API and it says 1.0.2 and I've added the roomListVars="true" to the config.
I'm setting a variable when the room is created, this variable shows up in the Admin tool and is visible in the "onRoomAdded" handler, but the variable doesn't appear in the "onRoomListUpdate" handler - checking the output window when Flash is running shows that no variables are being sent.
Edit-I should probably let you know that I'm using the AS1 version in Flash MX.
Posted: 16 May 2006, 11:41
by monkeypuzzle
I've solved my own problem and just in case other people are having the same problem, I'll let you know what I did wrong.
When editing the config file, I added the roomListVars="true" to the ROOM, when of course it should be added to the ZONE. Now everything works fine.
I have the same problem.
Posted: 26 Dec 2006, 16:09
by Carl
1. I'm setting some variables in my config file.
2. I made turned automatic variables on for the zone:
<Zone name="simpleChat" uCountUpdate="true" buddyList="20" maxUsers="50" customLogin="false" roomListVars="true">
3. With Smartfox debugger turned on, I can see my variables in the tracer window.
4. But with the smartfox.onRoomListUpdate handler, I can't see the variables; they all come in blank.
5. In the smartfox.onJoinRoom handler I can see the variables for the one room that i've joined, but I need to see th evariables for all the rooms.
I think this isn't working correctly. I'm on 1.5 pro demo.
thanks for any insights!
-Carl
Posted: 26 Dec 2006, 17:00
by Lapo
Here's a working example, based on SFS PRO 1.5
1 - Zone definition
Code: Select all
<Zone name="simpleChat" uCountUpdate="true" buddyList="20" maxUsers="4000" customLogin="false" roomListVars="true">
<Rooms>
<Room name="The Hall" maxUsers="50" isPrivate="false" isTemp="false" autoJoin="true" uCountUpdate="true">
<Vars>
<Var name="name" type="s" private="false">Animal</Var>
<Var name="job" type="s" private="false">Muppets drummer</Var>
</Vars>
</Room>
</Rooms>
</Zone>
2- CodeCreate a new Flash 8 document, and copy/paste the following code in the first frame. If necessary point your classpath to the API folder and then run the example.
Code: Select all
import it.gotoandplay.smartfoxserver.*
stop()
var ip:String = "127.0.0.1"
var port:Number = 9339
var zone:String = "simpleChat"
// Load the policy file from the server
System.security.loadPolicyFile("xmlsocket://" + ip + ":" + port)
var smartfox:SmartFoxClient = new SmartFoxClient()
smartfox.onConnection = handleConnection
smartfox.connect(ip, port)
//smartfox.debug = true
function handleConnection(success)
{
if (success)
{
trace(">> Connection successfull")
sendLogin()
}
else
{
trace("[ ERROR ]: Can't connect!")
}
}
function sendLogin()
{
smartfox.login(zone, "")
}
smartfox.onLogin = function(resObj:Object)
{
if (resObj.success)
{
// Login Successfull
trace(">> Login successfull. Nickname: " + resObj.name)
}
else
{
trace("[ ERROR ]: Login error. Server said: " + resObj.error)
}
}
smartfox.onRoomListUpdate = function(roomList:Object)
{
trace(">> Received the list of rooms\n")
trace("\tRoom List:")
trace("\t--------------------------------------------")
// Show the list of rooms
for (var i in roomList)
{
var r:Room = roomList[i]
trace("\t" + r.getName())
var o = r.getVariables()
for (var j:String in o)
trace("\t\t" + j + ": " + o[j])
}
// a blank line
trace("")
// Join the default room
this.autoJoin()
}
smartfox.onJoinRoom = function(roomObj:Room)
{
trace(">> Room: '" + roomObj.getName() + "' joined successfully")
}
smartfox.onJoinRoomError = function(errorMsg)
{
trace("[ ERROR ]: Error joining the room. Server said: " + errorMsg)
}
smartfox.onConnectionLost = function()
{
trace("[ ERROR ]: Connection with server was lost")
}
3- Example output
The above code is taken from the provided AS 2 template, found in our documentation. It will connect to the server, receive the list of rooms and dump the room variables and finally join a room.
Here's my output in the Flash output window:
>> Connection successfull
>> Login successfull. Nickname: guest_12
SET RVAR --> job
SET RVAR --> name
>> Received the list of rooms
Room List:
--------------------------------------------
The Hall
name: Animal
job: Muppets drummer
>> Room: 'The Hall' joined successfully
The test was done using a freshly installed SFS PRO 1.5
As you can see the variables for "The Hall" room are correctly shown in the trace.
Good luck
Thanks! .....And a question
Posted: 27 Dec 2006, 19:13
by Carl
Thanks for the detailed example. I was able to break off a function that returned my variables properly. It's great that it works, but I'm not completely sure WHY it works, or rather why what I was trying gave me no results at all. I'm sure it's because I havn't worked with objects much, but I cant' understand why when I do this:
var Lvars = Lroom.getVariables("GameType");
trace ("variables..."+ Lvars)
....I get an empty string as a result:
variables...
But when I go on to do this, as you showed me:
var Ltype = ExtractObject(Lvars);
trace (Ltype)
and....
ExtractObject = function (obj:Object) {
for (var i in obj) {
return (obj[i]);
}
};
I get a result? This is what was throwing me off, because when I see that "Lvars" variable is essentially empty or blank, I wouldn't have expected to be able to extract any information out of it. At the very least I would have expected the cryptic and uninformative "[object, object]" that I normally get when trying to directly trace an incoming object. I made a "traceobject()" function for opening these things up into the output window, but in this case I didn't think I had anything to extract.
Sorry for my ignorance of these things, but any help is appreciated from anyone in understanding this stuff. I'm next searching up on objects on kirupa.