Is it possible for a datablock to inherit methods ?
by suddysud aka mrclean · in Torque Game Engine · 02/20/2006 (11:47 pm) · 7 replies
Is it possible for a datablock to inherit methods ?
Here is the datablock in the fps sample.
Now if I just try to use this datablock it won't move around the path because it doesn't have onReachDestination. But rather than rewriting onReachDestination, I would like to inherit it?
Any ideas on that?
Thanks in advance
Stev
Here is the datablock in the fps sample.
datablock PlayerData(DemoPlayer : PlayerBody)
{
shootingDelay = 2000;
};Here is an example of the methodfunction DemoPlayer::onReachDestination(%this,%obj)
{
// Moves to the next node on the path.
// Override for all player. Normally we'd override this for only
// a specific player datablock or class of players.
if (%obj.path !$= "") {
if (%obj.currentNode == %obj.targetNode)
%this.onEndOfPath(%obj,%obj.path);
else
%obj.moveToNextNode();
}
}Is it possible for me to do something like this ? datablock PlayerData(FatDemoPlayer : PlayerBody)
{
maxForwardSpeed = 2;
maxBackwardSpeed = 2;
};Now if I just try to use this datablock it won't move around the path because it doesn't have onReachDestination. But rather than rewriting onReachDestination, I would like to inherit it?
Any ideas on that?
Thanks in advance
Stev
#2
I'd definitly like to know how a new datablock can inherit not only the properties but also the static methods
02/21/2006 (12:34 pm)
Please let me know. I'd definitly like to know how a new datablock can inherit not only the properties but also the static methods
#3
but i do see what seems to be a typo in your code -
i think you want this:
instead of this:
02/21/2006 (12:48 pm)
I don't actually know the answer,but i do see what seems to be a typo in your code -
i think you want this:
datablock PlayerData(FatDemoPlayer : DemoPlayer)
instead of this:
datablock PlayerData(FatDemoPlayer : PlayerBody)
#4
datablock PlayerData(PlayerBody){..}
Then in aiplayer.cs, DemoPlayer inherits from PlayerBody with the statement
datablock PlayerData(DemoPlayer : PlayerBody){..}
So my FatDemoPlayer inherits from DemoPlayer with the statement
datablock PlayerData(FatDemoPlayer : DemoPlayer){...}
I think FatDemoPlayer could have inherited from either DemoPlayer or PlayerBody.
-------------------
Once again, I'm just trying to figure out how to make new datablocks that inherit not only properties but also those methods/functions.
I notice something interesting in player.cs at the bottom there are these functions
I was wondering if these functions were related to the PlayerData block. and DemoBody might inherit them.
Does anyone know ?
Thanks in advance
02/21/2006 (1:55 pm)
No that wasn't a typo. In player.cs you have the original datablock PlayerBodydatablock PlayerData(PlayerBody){..}
Then in aiplayer.cs, DemoPlayer inherits from PlayerBody with the statement
datablock PlayerData(DemoPlayer : PlayerBody){..}
So my FatDemoPlayer inherits from DemoPlayer with the statement
datablock PlayerData(FatDemoPlayer : DemoPlayer){...}
I think FatDemoPlayer could have inherited from either DemoPlayer or PlayerBody.
-------------------
Once again, I'm just trying to figure out how to make new datablocks that inherit not only properties but also those methods/functions.
I notice something interesting in player.cs at the bottom there are these functions
function Player::playDeathAnimation(%this)
{
if (%this.deathIdx++ > 11)
%this.deathIdx = 1;
%this.setActionThread("Death" @ %this.deathIdx);
}
function Player::playCelAnimation(%this,%anim)
{
if (%this.getState() !$= "Dead")
%this.setActionThread("cel"@%anim);
}I was wondering if these functions were related to the PlayerData block. and DemoBody might inherit them.
Does anyone know ?
Thanks in advance
#5
right, except that in your original post you have
.. or i'm hallucinating or something. it's possible.
02/21/2006 (1:59 pm)
Quote:
So my FatDemoPlayer inherits from DemoPlayer with the statement
datablock PlayerData(FatDemoPlayer : DemoPlayer){...}
right, except that in your original post you have
Quote:
datablock PlayerData(FatDemoPlayer : PlayerBody){...}
.. or i'm hallucinating or something. it's possible.
#6
02/21/2006 (2:03 pm)
I think your problem may be that TGE (i use 1.3) only allows for 1 level of script inheritance. I think we used this resource to allow multiple levels of script inheritance: www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6335
#7
But I'm glad you understand the question though.
Owen thanks for the reference.
I'm using TGE 1.4 and i don't think it has this multiple levels of script inheritance.
I notice on the player.cs file that comes with 1.4 there is a datablock called PlayerData(PlayerBody)
and at the bottom there are these functions like
Are these functions part of the PlayerData Class in some way.
This looks like an example of the inheritance.
and the Naming convention looks related PlayerData and Player Namespace. Any relation?
Is this a special way to create functions for a class of DataBlocks.
I could work with 1 level of script inheritance if i could figure out how it works.
Thanks in advance for help
02/21/2006 (2:26 pm)
Orion you are right. I Missed that. But I'm glad you understand the question though.
Owen thanks for the reference.
I'm using TGE 1.4 and i don't think it has this multiple levels of script inheritance.
I notice on the player.cs file that comes with 1.4 there is a datablock called PlayerData(PlayerBody)
and at the bottom there are these functions like
function Player::playDeathAnimation(%this)
{
if (%this.deathIdx++ > 11)
%this.deathIdx = 1;
%this.setActionThread("Death" @ %this.deathIdx);
}
function Player::playCelAnimation(%this,%anim)
{
if (%this.getState() !$= "Dead")
%this.setActionThread("cel"@%anim);
}
//----------------------------------------------------------------------------
function Player::playDeathCry( %this )
{
%this.playAudio(0,DeathCrySound);
}
function Player::playPain( %this )
{
%this.playAudio(0,PainCrySound);
}Are these functions part of the PlayerData Class in some way.
This looks like an example of the inheritance.
and the Naming convention looks related PlayerData and Player Namespace. Any relation?
Is this a special way to create functions for a class of DataBlocks.
I could work with 1 level of script inheritance if i could figure out how it works.
Thanks in advance for help
Torque Owner Tim Heldna
Theoretically something like this should work...
I'll have to look into it and get back to you