Game Development Community

Unable to find object: '' attempting to call function 'setDataBlock'???

by Ahsan Muzaheed · in Torque 3D Beginner · 06/21/2011 (6:52 pm) · 7 replies

i was trying to change player model at game play.i have done this:

have created a file changePlayer.cs in \game\scripts\server\changePlayer.cs

code in changePlayer.cs:

function createPlayer(%this, %spawnPoint)
{
$myGlobal = %player;
$myGlobal.setDataBlock(GideonData);
}
moveMap.bind(keyboard, "y", createPlayer);

then
exeing in game\scripts\server\scriptExec.cs
by
exec("./changePlayer.cs");

but it always showing this:
scripts/server/chnagePlayer.cs (5): Unable to find object: '' attempting to call function 'setDataBlock'


not only here.always when i use setDataBlock function.

About the author

Torque 3D enthusiastic since 2010.Have been working in several T3D projects besides of Unreal Engine 4 and Unity 3D. NEED a hand with your project? SHoot me a mail. http://www.garagegames.com/community/forums /viewthread/138437/


#1
06/21/2011 (7:18 pm)
still do not know why that error was showing.but this code has worked:

function serverCmdchangePlayer(%client)
{
%client.player.setDatablock(GideonData);
}

moveMap.bindCmd(keyboard, "y", "commandToServer('changePlayer');", "");

#2
06/21/2011 (7:53 pm)
function createPlayer(%this, %spawnPoint)
{
$myGlobal = %player;
$myGlobal.setDataBlock(GideonData);
}
moveMap.bind(keyboard, "y", createPlayer);

You have not set %player to anything in that code. Maybe you mean $myGlobal = %this; ?
#3
06/21/2011 (9:33 pm)
"You have not set %player to anything in that code. Maybe you mean $myGlobal = %this; ? "
what means by "$myGlobal = %player;" is not it means "set %player to $myGlobal".

i thought %player is equal to %client.player
--------------------------------------------------------
question1:
in present i am trying to make it possible using bind() not using bindCmd().what to fix here:

function createPlayer(%client)
{
%client.player.setDatablock(GideonData);
}
moveMap.bind(keyboard, "F12", createPlayer);


question2:
is code with bind() have to exe in client side files and bindCmd() in server side files?

question3:
in c++ "this" means object which calls a function.in torque script what it means(player,client,server or anything else)?

#4
06/22/2011 (7:08 am)
Any variable inside a Function that is [ %var ] is a LOCAL var
Any Variable defined as [ $var ] is a Global.

A [ %this ] may or may not be assigned by default...
example:
function VehicleData::onDamage(%this, %obj)
Has the %this assigned by the C++ code that calls it:
IMPLEMENT_CALLBACK( ShapeBaseData, onDamage, void, ( ShapeBase* obj, F32 delta ), ( obj, delta ),
The C++ code assigns [ ShapeBase* obj ] to the local var [ %this ]
when it calls that function.

your function:
function createPlayer(%client)
{
%client.player.setDatablock(GideonData);
}
moveMap.bind(keyboard, "F12", createPlayer);

Has no C++ code calling it so you need to assign something to that
var [ %client ] when you call it..
moveMap.bindCmd(keyboard, "F12", "createPlayer(ServerConnection);","");

ServerConnection is the Default Client side Global object that
holds the clientID.

bind( and bindCmd( are BOTH client side
bind( is basically a Toggle KeyUp/KeyDown
bindCmd( is calling a function with specific values sent
So either could be used for this...

bind(..) with nothing but Key Up/Down checks, so all data must be in
the Function, not sent..
bindCmd(..) to send what ya want during the keypress

Example:
function toggleFirstPerson(%val)
{
   if (%val)
   {
     ServerConnection.setFirstPerson(!ServerConnection.isFirstPerson());
   }
}

so take it to the next step:

$spawnPoint = "myspawnpoint" //Need to set this up somehow
$Client::clientID = ServerConnection;

function createPlayer(%val)
{
  if(%val)
  {
    $myGlobal = $Client::clientID.player;
    $myGlobal.setDataBlock(GideonData);
  }
}
moveMap.bind(keyboard, "y", createPlayer);

That will only activate on the down press by checking (%val)
....

Now after all that, this would be better calling a Server command
so the cahnges are networked..

//Client code in default.bind.cs
function createPlayer(%val)
{
  if(%val)
  {
    commandToServer('createPlayerCall')
  }
}
moveMap.bind(keyboard, "y", createPlayer);

//Server side in scripts/server/commands.cs
function serverCmdcreatePlayerCall(%client)
{
   // Get the player object
   %player = %client.player;
   ....
   ....
}

The (%client) var is assigned in C++ by using the commandToServer(..)
which sends the ClientID during the call to the server...
#5
06/22/2011 (7:34 am)
Main thing to remember is that scripting is tricky as it has
no real checking on the Variables your using :)
And as this engine has the Client/Server code so intermingled it
is easy to get lost, dazed, and confused. I get that way sometimes
myself.

Even if your doing this as a single player only game, it is best to
not change things on the client side.
#6
06/22/2011 (8:05 am)
john,thank you so much.that was completely new direction about torque script to me.i have to think all of them.currently busy with my exam.
beside studying i was trying to change a code used bindCmd() to bind().
may be now i will be able to do it.here it is what i was trying:


function serverCmdchangePlayer(%client)
{
%client.player.setDatablock(GideonData);
}
moveMap.bindCmd(keyboard, "F12", "commandToServer('changePlayer');", "");
it works fine,no matter where i exe it(both in client and server side) .

i have converted it to:
function changePlayer(%client)
{
%client.player.setDatablock(GideonData);
}
moveMap.bind(keyboard, "F12",changePlayer);

it always shows(both in client and server side):
Unable to find object: '' attempting to call function 'setDataBlock'.

i will try to figure out it.now busy with my study.again very very thanks for that long explanation.
#7
06/22/2011 (11:24 am)
yeah, the first one works both client/server IF your running
in single player mode...
this changes when you switch to a dedicated or hosted situation.
In singleplayer you have ALL the code accessible as it loads both server/client.

The second one still does not have the ( %client ) var assigned
with the moveMap.bind(keyboard, "F12",changePlayer);

Remember: The bind(...) only sends the (%val) which is either true/false
True = keydown / false = keyup (basically just a Flag value)