setUserVariables error

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

luoruize
Posts: 21
Joined: 25 Aug 2009, 11:07

setUserVariables error

Postby luoruize » 09 Sep 2009, 11:58

Hey,

I'm trying to use the setUserVariables, and receiving the following exception:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at it.gotoandplay.smartfoxserver::SmartFoxClient/setUserVariables()
at mainGame_sfs_fla::MainTimeline/setPlayerVariables()
at mainGame_sfs_fla::MainTimeline/frame70()


The game uses a custom join, and I'm trying to send the variables after I'm logged into a game room. After reading some posts about this issue, I added the following lines after the player joins the room:

Code: Select all

trace("My user ID is: " + smartFox.myUserId);
trace("I logged in as: " + smartFox.myUserName);


This is what I get in the output window:

My user ID is: -1
I logged in as:


I tried getting the room list again, which didn't help.

Whenever a player logs into the game, he first logs into the lobby so that several functions can be executed, and then he is transferred to another room. I added the lines to show the userId and name after joining the lobby, too, with the same results. It feels like the client loses track of which user it is handling...
Biff_Cornwall
Posts: 29
Joined: 07 Aug 2009, 17:54

Postby Biff_Cornwall » 09 Sep 2009, 15:37

You need to make sure that you are setting the smartFox.myUserId and smartFox.myUserName in your custom login handler. If you don't, you will get errors throughout your application.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 10 Sep 2009, 08:20

Usually, when the id is -1, it means that the user isn't logged in a room. It has already happened to me.
luoruize
Posts: 21
Joined: 25 Aug 2009, 11:07

Postby luoruize » 10 Sep 2009, 08:36

I know, but that's the thing - the player is logged... I can check it both in the admin tool, and when I get the room list. I tried assigning the relevant data to both myUserId and myUserName, but nothing worked. In the end, I just created an extension command that does this, and it works perfectly. It's just annoying to me that I can't use the built in command.
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 10 Sep 2009, 09:08

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at it.gotoandplay.smartfoxserver::SmartFoxClient/setUserVariables()
at mainGame_sfs_fla::MainTimeline/setPlayerVariables()
at mainGame_sfs_fla::MainTimeline/frame70()


Could you post the script of frame 70 pls?
luoruize
Posts: 21
Joined: 25 Aug 2009, 11:07

Postby luoruize » 10 Sep 2009, 17:14

I think I know where the problem lies. The room I'm creating is a game room (it has to be one). I noticed, after tracing the events received by the server, that it first joins the new room, and only then sends a userExit event to the server, which means that for a moment the player is in more than one room.
I saw on the room architecture doc that there's a property called exitCurrent, which forces the user to first leave the room he's in before joining the next, but I couldn't find an example of how to use it. Any suggestion?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 11 Sep 2009, 17:31

I think I know where the problem lies. The room I'm creating is a game room (it has to be one). I noticed, after tracing the events received by the server, that it first joins the new room, and only then sends a userExit event to the server, which means that for a moment the player is in more than one room.

This is correct. First the server joins the user in the new room, if this succeeds it removes the User from the previous room. If it fails nothing will happen and the User will remain in the original Room.

I saw on the room architecture doc that there's a property called exitCurrent, which forces the user to first leave the room he's in before joining the next, but I couldn't find an example of how to use it. Any suggestion?

the exitCurrent flag simply indicates if you wish to leave the current room or not.
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 87 guests