Page 1 of 1

Strange UserVariables Problem - On joining a game room.

Posted: 14 Nov 2010, 22:35
by bart4president.com
I have encountered an issue upon user variables being removed when rejoining a Game room (SFSGame).

This is an example snippet of code Im using upon joining a room to get variables:

Code: Select all

var players:Array = smartFox.lastJoinedRoom.playerList;
for each(var player:User in players){
    playerVariable = player.getVariable("variableName").getValue();
}
*Upon leaving and rejoining a game as a NON-creator, with the creator still present, variables are received fine (from the creator). I can leave and rejoin over and over, no problem.
*If I was the CREATOR of that room and I rejoin that room (happens when another user is present and the room isn't destroyed) the other user's variables DISAPPEAR. Even though I can confirm via the admin tool they are still present.
*After the above instance, if the other user leaves and rejoins the same room, that user then experiences the problem.

Yup you heard me right, they go poof as a

Code: Select all

trace(player.containsVariable("variableName"));
returns false

However, the wierd thing is.. is that variables that were created prior to joining that room.. such as in the main lobby.. such as "nickName" or "avatar" still exist. Just the variables that were made for game functions disappear .

If there is an immediate "gotcha" that you see let me know, if not and you need me to get deep and post some code, let me know.

***** UPDATE *****

I seem to have narrowed it down to this:

If I join a room, player.getVariable("myGameVariable").getValue() works for OTHER players in the room as it seems to be transparently displaying the variables.

However, it WON'T display MY player's variables .. as if they don't exist on myPlayer.getVariable("myGameVariable") . I even added a button to get the variables in question on click to test if its just a timing problem and its seems that it isn't. It persistently will not display my game variables whether i join a room or join a room a just created with my player, click the refresh button every time. No joy.

Note: Variables still show up correctly and accurately on the serverside via the admin tool. So something is either removing them (i checked and rechecked my client side code and found nothing that would do this) or they are just not being updated when I join a room.

However.. variables created such as "nickName" and "avatar" still show up persistently fine. (these are created upon choosing a character after logging in)

I am really at a loss here :(

Posted: 15 Nov 2010, 17:51
by bart4president.com
Anyone have any thoughts on this?? I am stuck as its breaking a basic necessary function in my game :( :(

Posted: 15 Nov 2010, 18:29
by Alex
Does you room has the flag USER_VARIABLES_UPDATE_EVENT?

Posted: 15 Nov 2010, 18:33
by bart4president.com
Yes I investigated that.. and I flagged it to yes (just incase as it was set to yes by default i think).. and it didn't seem to have an effect.

Posted: 15 Nov 2010, 23:56
by bart4president.com
I believe i found my answer here:
http://forums.smartfoxserver.com/viewto ... rvariables

as I am setting variables in extensions.. not properly I see.

** UPDATE **

CONFIRMED.. that was the issue. Moral of the story for your fellow noobs out there.

USE getAPI().setUserVariables ... etc.
or the roof will fall on your head.


As your user/room variables on your client will NOT update unless you use getAPI().