Game Development Community

Adding to player datablock

by Mike Stoddart · in Torque Game Engine · 07/12/2002 (10:34 am) · 15 replies

If I want to add a new value to the player's datablock, do I need to also add this variable to the Player class (player.cc)? I think the answer is yes, but I just wanted someone to clear this up for me.

Thanks

#1
07/12/2002 (10:42 am)
I've added variables to weapon datablocks (no C-code) and referenced them in other parts of the script. I would think the player datablock would be similar. I guess it depends on what it is you're adding and how it'll be used.

Edit:
I think if you're using the added variable in script functions or whatever it will work fine. If you need to use the added variable in the C-code some place then that would be a problem.
#2
07/12/2002 (10:47 am)
I want to store a function name in the player datablock:

datablock PlayerData(futuristicScout)
{
  functionName = "someFunction";
}

Then I want to be able to call that function on the server from elsewhere in the scripts using the eval function. I haven't tried it yet, but I dumped the player class out, and couldn't see any reference to this new variable functionName that I added.

Thanks
#3
07/12/2002 (10:51 am)
hmmm...can't say I've tried that. Maybe someone else would know. Interesting idea though.
#4
07/12/2002 (12:07 pm)
I dont know what you mean mike, but if you want to add a method function to your player class just do

function futuristic::myfunction()
{

}

and then whenever you have a futristic player class you'll be able to do %player.myfunction();
Or you can define it as a general player class like:

function Player::myfunction()
{

}

in this case the function will be available to any player class and not only the futuristic player datablock...
Hope that's what u meant :\
#5
07/12/2002 (12:30 pm)
You mean:

futuristicScout::someMethod()
{
}

You mean it's that easy?? Man, I've been bashing my head against the wall with this! :)

I want an equipPlayer function in each individual player class, so that the logic for equipping that player (when they join a game) is contained with each different class.
#6
07/12/2002 (2:06 pm)
Yeah, just about that easy. Implement

function ::someMethod(...)

for each type, then you can call

%player.someMethod(...);

for any reference to a player object. Polymorphism .
#7
07/13/2002 (11:17 am)
No no, I thought you meant I could just add that in the script. It didn't occur to me that you were referring to the C++ Player class! :P

I was hoping to find a solution that didn't require modification to the player class C++ source.

My eagerness chip overrode my sensible chip and turned me into a gibbering idiot. :P
#8
07/13/2002 (1:31 pm)
Zear was referring to the scripting language, for example take the following code.

datablock PlayerData(futuristicScout)
{
 className = Armor;
 [Datablock data here]
}

datablock PlayerData(fantasyScout)
{
 className = Armor;
 [Datablock data here]
}


datablock PlayerData(Scout)
{
 className = Armor;
 [Datablock data here]
}

function Armor::dothis(%this) {
  Echo "Default doThis function called";
}

function futuristicScout::dothis(%this) {
  Echo "Futuristic Scout doThis function called";
}

function fantasyScout::dothis(%this) {
  Echo "Fantasy Scout doThis function called";
  Parent::dothis(%this);
}

When you do a %player.doThis you will get 3 different outputs based on what playerdata object your player is using.

Scout -
Default doThis function called

futuristicScout -
Futuristic Scout doThis function called

fantasyScout -
Fantasy Scout doThis function called
Default doThis function called
#9
07/13/2002 (5:14 pm)
I'm pretty sure I tried that but the program said "Unknown command doThis". Note that I don't have a futuristicScout class in the C++ source code, only Player in player.cc/player.h.
#10
07/13/2002 (8:29 pm)
if you defined futuristicScout as the class name it will work.
Look at your player datablock you should see a line like:

className = Armor;

change that to show futuristicScout instead... you will be able to call futuristicScout:: member functions afterwards.
#11
07/13/2002 (8:37 pm)
Do I need to change anything when I new the player?

%player = new Player() {
      dataBlock = futuristicScout;
      client = %this;
   };

I'm still geting "unknown command doThis".
#12
07/13/2002 (8:43 pm)
I don't know of this helps any:

unknown command doThis.
Player->ShapeBase->GameBase->SceneObject->NetObject->SimObject
#13
07/14/2002 (2:27 am)
with the datablock definition above, you build up the following hierarchy:
futuristicScout->Armor->PlayerData->ShapeBaseData->GameBaseData->...
but you try to call a function of player. You could try this:
%player.getDataBlock().doThis();
I didn't try this out, so please correct me if I'm wrong.

Alex
#14
07/14/2002 (10:09 am)
Alexander: thanks, that worked perfectly! Thanks for your help everyone.
#15
02/25/2007 (10:24 am)
I'm trying to add an array as a member. So when you do $blabla.setAggro[3](25); Is this possible to do?

function Actor::setAggro(%this, %target, %damage)
{
for (%x=0;%x<10;%x++)
{
if (%this.setAggro[%x]() == "")
{
%this.setAggro[%x]() = %target;
%x = 10;
}
}
}

function Actor::getAggro(%this, %target, %damage)
{
return %this.aggro[%x]();
}