Game Development Community

Player data access (client)

by combitz · in Torque Game Engine · 01/02/2009 (1:13 pm) · 7 replies

I am reading some more of the documentation and having problems with some earlier things so I decided to come back to this player data issue:

The official documentation says I can run this in the console:

$player_name = "myGuy";
$player_id = $player_name.getID();

but I get the error:

(0): unable to find object. attempting to call 'getId'


if I echo out $playername I get "myGuy" so the object does exist

I am trying to access each player or clients unique id as I need to see who has taken control of which areas. I have the display system working but I can't seem to access any part of the client data to store and check for a win condition.

I'm reading it from here:
http://www.garagegames.com/docs/tge/official/index.html?content/documentation/Artists/GUI/Overview.html

I really don't understand why I would be getting a issue with this but I have read in several places that the players position can be accessed in a similar way with $player_name.position but I get no value back at all.

any help?

cheers

#1
01/03/2009 (8:44 am)
$player_id = myGuy.getID();
#2
01/03/2009 (11:29 am)
Thanks Picasso but this fails for me. FPS game works fine and no issues with editor or console apart from scripts don't seem to work.

I typed the following:

$p = "myGuy";
echo($p);

output was
myGuy

but when I now type
$player_id = myGuy.getID();

I get the error :
(0): unable to find object 'myGuy' attempting to call function 'getId'


I am using TGE_1_5_2 and totally flumaxed by this issue
#3
01/03/2009 (11:35 am)
Seems like $player_id is already in use somewhere else...
#4
01/03/2009 (12:09 pm)
It does not matter what variable name I try to assign the returned value of the function call to, I have tried $m instead of $player_id and it still fails.

It is the same with the default FPS starter ???
#5
01/03/2009 (1:07 pm)
Go to server\scripts\game.cs

function GameConnection::createPlayer(%this, %spawnPoint)
{...........

   // find this:
   // Create the player object
   %player = new Player() {
      dataBlock = %this.playerDB;
      client = %this;
   };
   MissionCleanup.add(%player); 

   // Player setup...
   %player.setTransform(%spawnPoint);
   %player.setEnergyLevel(%player.getDataBlock().maxEnergy);
   %player.setShapeName(%this.name);

   // now the player instance is in heap
   // add here:
   $player1 = %this.player; // move to global scope

.....
}

now in console write:
echo($player1.getid());
#6
01/03/2009 (2:03 pm)
Thanks Picasso.

I can try to access some player data now.


is there a reason why no one else seems to have this issue?
#7
01/03/2009 (2:14 pm)
(0): unable to find object 'myGuy' attempting to call function 'getId'

Is because you are assigning $player_name to be equal to the string "MyGuy". When you type "$player_name.getID();" it is essentially the same as typing "MyGuy.getID();". The most likely problem is that your player is not named "MyGuy" your player has a different (or more likely, NULL) name. So MyGuy does not exist, thus having no ID.