PDA

View Full Version : Receiving an object in a plugin



crusader
06-25-2004, 04:26 PM
I have one more question on plugins.

I'm trying to send an object from the client to the server-side plugin in (an objects which contains the move that a player played on his turn)
and I want the plugin to forward it to the opponent and all spectators.

The problem is that I cannot receive properly the object the clients sends to the plugin.

The client uses this:



var parameters = {};
parameters.obj = object;
_root.es.pluginRequest (PluginName', 'Move', object);


And the plugin uses this:



function pluginRequest(hash) {
var user = hash.get("ExecutingUserName");
var method = hash.get("Method");

// Move received
if (method == "Move") {
var obj = Object(hash.get("obj"));
var arr = arrPlayers;
sendMove (obj, arr);
}
}



var obj = Object(hash.get("obj"));
This is the 'key' line in the whole thing. I guess I'm not using the get function properly and the object comes in as null.

Please, any suggestions?

jobem
06-25-2004, 07:11 PM
Hi Dimitrios,

What kind of object are you sending? Just an object with some variables? Remember that when interacting with plug-ins you can only send/receive variables. You can't send an object of objects, or an array, etc.



var ob = new Object();
ob.firstName = "jobe";
ob.lastName = "Makar";

Or as seen in the documentation


parameters = new Object();
parameters.startx = 200;
parameters.endx = 300;
parameters.starty = 37;
parameters.endy = 110;
parameters.color = "blue";
es.pluginRequest("WhiteBoardScriptPlugin", "DrawLine", parameters);


In your plugin you'd have code like this


function pluginRequest(hash) {
var user = hash.get("ExecutingUserName");
var method = hash.get("Method");

// Move received
if (method == "DrawLine") {
var startx = Number(hash.get("startx"));
var starty = Number(hash.get("starty"));
var endx = Number(hash.get("endx"));
var endy = Number(hash.get("endx"));
}
}

crusader
06-25-2004, 07:22 PM
Ok Jobe, thank you.

I was trying to send an object inside the parameters object, so that was the reason why it failed.

I'll implement this the way you are suggesting.

Thanks again!