extension log "TypeError" why?

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

Moderators: Lapo, Bax

User avatar
mhdside
Posts: 236
Joined: 04 May 2008, 07:57
Location: Egypt
Contact:

extension log "TypeError" why?

Postby mhdside » 28 Nov 2011, 12:52

Hi,

I checked my smart fox log files and I found the following error logged so many times in a room extension:

Code: Select all

INFO   | jvm 1    | 2011/11/26 00:20:39 | 00:20:38.969 - [ WARNING ] > Error in extension [ xt31.as ]: TypeError: Cannot call method "getId" of null (my_ext.as#1965) Internal: 388 -- Line number: 388 in file: my_ext.as


Here is a part of my extension focussed at showing the variable "room" that becomes null:

Code: Select all

var room;

function init()
{
   room = _server.getCurrentRoom();
}

function handleInternalEvent(e)
{
   if(e.name == "userExit" || e.name == "userLost")
   {
      if (e.oldPlayerIndex > -1)
      {
         var res = {};
         res.rm = room.getId();
         ...
      }
   }
}


The extension is a room extension.

The question: what could set the variable "room" to null?

assuming the left player is the last one in the room and the room is destroying, I think the vaiable "room" should still be valid till after the function call is done, no?
Mahmoud Badri
Senior actionscript developer
http://www.el3ab.com
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Nov 2011, 09:53

What version of SFS PRO are we talking about?
Also which line of the code is causing the issue? You didn't specify
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
mhdside
Posts: 236
Joined: 04 May 2008, 07:57
Location: Egypt
Contact:

Postby mhdside » 29 Nov 2011, 10:02

What version of SFS PRO are we talking about?

SFS 1.6.9



Also which line of the code is causing the issue? You didn't specify

Code: Select all

res.rm = room.getId();

The problem is that "room" is null and I don`t see the reason why it could be nullified.
Mahmoud Badri

Senior actionscript developer

http://www.el3ab.com
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Nov 2011, 10:16

Then it's your room object that is null. Are you sure you are running that code within the scope of a Room Level Extension?
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
mhdside
Posts: 236
Joined: 04 May 2008, 07:57
Location: Egypt
Contact:

Postby mhdside » 29 Nov 2011, 11:23

Are you sure you are running that code within the scope of a Room Level Extension?

Yes, very sure, it is a room level extension for a game room. The extension is attached to the game before it is dynamically created.
Mahmoud Badri

Senior actionscript developer

http://www.el3ab.com
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 29 Nov 2011, 15:09

Without being able to see the code in action it's not possible to say, a I am sorry. Evidently something info is missing here.
Anyways you can use a simple workaround, save the ID of the Room in the init() as well.

Code: Select all

var room
var roomID

function init()
{
   room = _server.getCurrentRoom();
   roomId = room.getId()
}

function handleInternalEvent(e)
{
   if(e.name == "userExit" || e.name == "userLost")
   {
      if (e.oldPlayerIndex > -1)
      {
         var res = {};
         res.rm = roomId;
         ...
      }
   }
}
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
mhdside
Posts: 236
Joined: 04 May 2008, 07:57
Location: Egypt
Contact:

Postby mhdside » 29 Nov 2011, 17:10

Actually this simple extension I provided is all there is for the var "room" scope. I know it doesnt make sense and it shouldn`t be null. I have memory problems with the server and sometimes it halts, so maybe it happens at that time. Also your simple workaround is certainly a good idea.

thanks!
Mahmoud Badri

Senior actionscript developer

http://www.el3ab.com

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 42 guests