Page 1 of 1

Rhino Usage Warning: Missed Context.javaToJS() conversion

Posted: 07 Dec 2009, 09:23
by MoonChild
I keep getting this warning:
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object it.gotoandplay.smartfoxserver.data.User@12fb62c of
class it.gotoandplay.smartfoxserver.data.User where it expected String, Number,
Boolean or Scriptable instance. Please check your code for missing Context.java
ToJS() call.
I tried to google for an answer but I haven't found anything that could help me.

Posted: 07 Dec 2009, 14:55
by Lapo
Hi,
it looks like you are passing the wrong object in a function call. Probably a User object instead of a userId which is expected as a number.
If you also have the line number of the error please double check your code to make sure you are passing the right arguments.

Posted: 08 Dec 2009, 10:26
by MoonChild
Lapo wrote:Hi,
it looks like you are passing the wrong object in a function call. Probably a User object instead of a userId which is expected as a number.
If you also have the line number of the error please double check your code to make sure you are passing the right arguments.
The warning seems to appear everytime this function gets called

Code: Select all

	//Send Bullet Data
	if (cmd == "send.bulletdata")
	{
		var myZone = _server.getCurrentZone();
		var myRoom = myZone.getRoom(fromRoom);
		var playerID = user.getPlayerIndex();
		var usersInRoom = myRoom.getAllUsers();
		var usersToRespond = new Array();
		
		for (index = 0; index<usersInRoom.length; index++) {
			if (user != usersInRoom[index]) {
				usersToRespond.push( usersInRoom[index] );
			}
		}
		var response = {};
		response._cmd = "receive.bulletdata";
		response.pID = playerID;
		response.pObject = params;
		_server.sendResponse(response, fromRoom, null, myRoom.getAllUsers());
	}

Posted: 08 Dec 2009, 16:45
by Lapo
The for loop that you use to populate the usersToRespond array is not necessary. The Room object exposes a method called getAllUsersButOne().

It works like this:
var usersToRespond = room.getAllUsersButOne(myUser)
It will return an array with all the users in the room except myUser.

Maybe the error is caused in the foor loop. Try removing it and use the above example instead.

Posted: 09 Dec 2009, 11:46
by MoonChild
Lapo wrote:The for loop that you use to populate the usersToRespond array is not necessary. The Room object exposes a method called getAllUsersButOne().

It works like this:
var usersToRespond = room.getAllUsersButOne(myUser)
It will return an array with all the users in the room except myUser.

Maybe the error is caused in the foor loop. Try removing it and use the above example instead.
Well it's replaced and I'm not getting that error anymore. So thanks a lot for your help! :)