User Variables

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
Nelagend
Posts: 9
Joined: 08 Aug 2010, 18:09

User Variables

Post by Nelagend »

I'm trying to tell an ActionScript 3.0 extension code to set some room or user variables to allow a "lobby" room to tell a game room what characters the players want to load. I've tried doing it with both room and user variables and neither call seems to work. Here's the user variable code with traces.

Code: Select all

var uVars = {}
uVars.chars = tempArray
trace("Our temp array is " + tempArray)
trace("This makes uVars "+uVars.chars)
_server.setUserVariables(temp1,uVars)
trace("Team 1 user variable is " + temp1.getVariables())
Temp1 is a user object for the first player being sent to the new room.
The first trace returns just what tempArray is supposed to be, a listing of the characters the user wants to play in the room I'm sending them to.
The second trace is the same, as expected.
The third trace is an empty object. I've tried using getVariable("chars") and I get null.

The setUserVariables call agrees with the server documentation as far as I can see. Did I write something wrong, or do I need to wait for an event from the server that indicates that user variables are correctly set? If so, what event am I looking for?[/code]
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

That code looks fine, providing temp1 is valid.

temp1.getVariables() will return a java.util.HashMap. So you would get your 'chars' var like this: temp1.getVariables.get("chars").value, if my memory serves me right.

Alternatively, use temp1.getVariable("chars").value.
Smartfox's forum is my daily newspaper.
Nelagend
Posts: 9
Joined: 08 Aug 2010, 18:09

Post by Nelagend »

temp1 is definitely a User object, or at least responds to all other functions designed to run on User objects that I can trace.

Temp1.getVariables() should return a hash map, but it returned null.

I got the same type of behavior when I tried to set room variables this way - the line was processed but had no effect, or at least no instantaneous effect.

I found a workaround by using the user properties array, which fortunately does not have the same problem.

At this point the new room loads correctly server side, however, when the new room sends an extension response, the client doesn't react in any way I can trace, despite the fact that a room I create client side with the same extension as the new room gets reactions from the clients.

The only difference I can put my finger on is that the client created the rooms with working extensions, while the room that runs the extension code with no reaction from the client was created by another room's extension.

In each of these problems, traces are responding as if the code's running, except the effect (either changing a variable or telling the client to react) can't be observed. I'm sure it's something stupid I'm missing, but I've spent some hours twiddling, rereading the docs on the website, and searching for why with no success. Any ideas?

Edit: I kept looking and found that I'm getting funny behavior every time I start the client in one extension in one room and then move them to another extension in another room. It's as if the client needs to be told "Hi, you're now in THIS room, with THIS extension operating, so listen to it."
Nelagend
Posts: 9
Joined: 08 Aug 2010, 18:09

Post by Nelagend »

Code: Select all

[Sending]: <msg t='sys'><body action='joinRoom' r='15'><room id='16' pwd='' spec='0' leave='1' old='15' /></body></msg>
[ RECEIVED ]: <msg t='sys'><body action='joinOK' r='16'><pid id='1'/><vars /><uLs r='16'><u i='0' m='0' s='0' p='1'><n><![CDATA[Nelagend]]></n><vars></vars></u></uLs></body></msg>, (len: 165)
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at it.gotoandplay.smartfoxserver.handlers::SysHandler/handleJoinOk()[C:\SmartFoxServerPRO_1.6.6\Flash API\Actionscript 3.0\it\gotoandplay\smartfoxserver\handlers\SysHandler.as:232]
...... etc.
I finally thought to run the client itself in debug mode. The first line listed in this error message is in the Client API,

Code: Select all

currRoom.clearUserList()
After looking at my Variables list, I see that currRoom is indeed null, which crashed my client. Time to compare that received message before the crash to one that didn't cause a crash.

Code: Select all

[ RECEIVED ]: <msg t='sys'><body action='joinOK' r='15'><pid id='1'/><vars /><uLs r='15'><u i='0' m='0' s='0' p='1'><n><![CDATA[Nelagend]]></n><vars></vars></u></uLs></body></msg>, (len: 165)
[ RECEIVED ]: <msg t='xt'><body action='xtRes' r='-1'><![CDATA[<dataObj><var n='_cmd' t='s'>lobbyWelcome</var></dataObj>]]></body></msg>, (len: 122)
^That pair didn't crash the client...
[ RECEIVED ]: <msg t='sys'><body action='joinOK' r='16'><pid id='1'/><vars /><uLs r='16'><u i='0' m='0' s='0' p='1'><n><![CDATA[Nelagend]]></n><vars></vars></u></uLs></body></msg>, (len: 165)
^that one and the extension response that I *think* came with it did.
Looking at the debugger's variables pane, the variable 'roomId' is correctly reading 16. currRoom is null despite that the line before the Flash Client API's crash sets currRoom to sfs.getRoom(roomId)... which should be the room object of room 16, where the server just sent us to.

Sounds as if my problem is that getRoom(16) returned null? That doesn't necessarily make sense to me, but I don't know where else to look.
Nelagend
Posts: 9
Joined: 08 Aug 2010, 18:09

Post by Nelagend »

After days of bashing my head against this problem with no result, it's finally fixed.

The crash I found via debug was in sysHandler.as.
I was running SFS 1.6.6.
There is a new patch, 1.6.9, available to download.
That fixed it immediately.

I knew it was something stupid. :oops:
Post Reply