Datablock/Namespace, trying to make my own datablocks
by Cinder Games · in Torque Game Engine · 04/14/2007 (4:29 pm) · 10 replies
I'm trying to create my own datablocks for the partymembers in my project.
i'm spawning a character using something similiar to this
But once Bob is created, he's unable to cheer.
I hope it makes sense what i'm trying to do.
I want to have a whole set of custom functions just for partymembers, using the PartyMember class functions.
I've been trying several things for hours, including trying to use ClassName, but i'm unable to do what i want.
If i add a AIPlayer::Cheer() function, i'm able to call that, but thats not what i need. I need it to be accessable only to players with the PartyMember datablock.
datablock PlayerData(PartyMember : PlayerBody)
{
shootingDelay = 2000;
isMonster = 0;
Mspeed = 0;
};
function PartyMember::Cheer(){
error("Suck Sess");
}
datablock PlayerData(PartyMember1 : PartyMember){
shapeFile = "~/data/shapes/monsters/devilslug.dts";
};i'm spawning a character using something similiar to this
$bob = new AIPlayer(){datablock=PartyMember1;};But once Bob is created, he's unable to cheer.
<input> (0): Unknown command Cheer. Object (2025) AIPlayer -> Player -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject
I hope it makes sense what i'm trying to do.
I want to have a whole set of custom functions just for partymembers, using the PartyMember class functions.
I've been trying several things for hours, including trying to use ClassName, but i'm unable to do what i want.
If i add a AIPlayer::Cheer() function, i'm able to call that, but thats not what i need. I need it to be accessable only to players with the PartyMember datablock.
#2
04/15/2007 (7:10 am)
That doesn't seem right. If you notice the player uses the armor functions all over the place and never needs to call .getdatablock() to access them.
#3
I did make a mistake in my example, though.
You'd probably want to have the Cheer method take a parameter for the Player instance, and then call it like this:
04/15/2007 (7:17 am)
Well, 'Armor' is set as the script class of PlayerData, not player, and I'm not sure where you're seeing an Armor method called directly on a Player instance.I did make a mistake in my example, though.
You'd probably want to have the Cheer method take a parameter for the Player instance, and then call it like this:
function PartyMember::Cheer(%this,%obj)
{
%obj.doSomethingWithThePlayerInstance();
}
$bob.getDatablock().Cheer($bob);
#4
But an example would be damage.
%player.damage(etc)
can be called just like that.
yet, the function is armor::damage
04/15/2007 (7:24 am)
Well the functions are all over in player.cs.But an example would be damage.
%player.damage(etc)
can be called just like that.
yet, the function is armor::damage
#5
When you call %player.damage(etc...), it ends up calling into the default script method in ShapeBase:
And that is what calls the method in Armor. I think.
04/15/2007 (7:33 am)
That's a confusing one, and took me a few minutes to figure out.When you call %player.damage(etc...), it ends up calling into the default script method in ShapeBase:
function ShapeBase::damage(%this, %sourceObject, %position, %damage, %damageType)
{
// All damage applied by one object to another should go through this
// method. This function is provided to allow objects some chance of
// overriding or processing damage values and types. As opposed to
// having weapons call ShapeBase::applyDamage directly.
// Damage is redirected to the datablock, this is standard proceedure
// for many built in callbacks.
%this.getDataBlock().damage(%this, %sourceObject, %position, %damage, %damageType);
}And that is what calls the method in Armor. I think.
#6
Even using $bob.getdatablock().cheer() it does not work. Because cheer is setup PartyMember::cheer() and the datablock for bob is PartyMember1
04/15/2007 (7:46 am)
Well, alright. I guess torque script is alot more restricting then i thought.Even using $bob.getdatablock().cheer() it does not work. Because cheer is setup PartyMember::cheer() and the datablock for bob is PartyMember1
#7
Now you can make your call. It really isn't restrictive at all once you know how it all works.
04/15/2007 (7:51 am)
Just add this to the datablock:className = "PartyMember";
Now you can make your call. It really isn't restrictive at all once you know how it all works.
#8
I think there might be an issue with naming a datablock that you're copying the same as a script namespace you're inheriting from. I recall getting some sort of 'can't reassign class', etc... message when doing this.
What I'd do is assign the className of both PartyMember and PartyMember1 to something like 'PartyMemberCommon', and then put the cheer method in that script class, ie.,:
04/15/2007 (7:58 am)
@ZodI think there might be an issue with naming a datablock that you're copying the same as a script namespace you're inheriting from. I recall getting some sort of 'can't reassign class', etc... message when doing this.
What I'd do is assign the className of both PartyMember and PartyMember1 to something like 'PartyMemberCommon', and then put the cheer method in that script class, ie.,:
datablock PlayerData(PartyMember)
{
className = "PartyMemberCommon";
...
}
datablock PlayerData(PartyMember1: PartyMember)
{
...
}
function PartyMemberCommon:cheer(%this,%obj)
{
}
#9
well that's still no good. I did add in classname=PartyMember; on the datablock for PartyMember1.
04/15/2007 (7:58 am)
==>Partymember::cheer(); Suck Sess ==>$player.getdatablock().cheer(); <input> (0): Unknown command Cheer. Object PartyMember1(130) PlayerData -> ShapeBaseData -> GameBaseData -> SimDataBlock -> SimObject
well that's still no good. I did add in classname=PartyMember; on the datablock for PartyMember1.
datablock PlayerData(PartyMember1 : PartyMember){
shapeFile = "~/data/shapes/player/player.dts";
className=PartyMember;
};
#10
$player.getdatablock().cheer()
works
04/15/2007 (8:01 am)
Hmm alright, if i try the PartyMemberCommon Method..$player.getdatablock().cheer()
works
Torque Owner Brian Hill