Game Development Community

Script Inheritance Not Working

by Johnathan Moore · in RTS Starter Kit · 04/14/2006 (4:01 pm) · 2 replies

Hi,
I have only ever had this problem using the RTS kit, for some reason the inheritance of functions between datablocks and objects does not work but only for the functions I add. So just to test this I add the following function to rifleman.cs

function RTSUnitData::testfunction(%obj)
{
	echo("it works");
}

then I run, go into the console window and type 1450.testfunction();
and it returns

==>1450.testfunction();
<input> (0): Unknown command testfunction.
  Object (1450) RTSUnit -> Player -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject

I have functions I have made in player.cs so it is not because it is loaded after the datablock

If I have made a stupid error someone please put me out of my misery :)


EDIT:
It works when I enter the function like this

==>RTSUnitData::testfunction(1450);
it works

It is exactly the same using the original build

#1
04/15/2006 (4:14 am)
Quote:
It works when I enter the function like this

==>RTSUnitData::testfunction(1450);

That works because you're really just calling a function that happens to have the name "RTSUnitData::testFunction" eg in the above case "::" is just a part of the name.

Looking at the output when you run 1450.testfunction() suggests that 1450 is an RTSUnit and not a datablock of type RTSUnitData. So the function you are adding needs to be in the RTSUnit namespace (or player, shapebase etc) eg

function RTSUnit::testFunction(%this)
{
   echo("Hi Mum!");
}

then calling 1540.testFunction(); should work.

If you're wanting to keep the function as an extension of the datablock maybe to access something that is a part of the datablock then you could leave testFunction as part of the RTSUnitData and call the function on the datablock eg

1450.getDataBlock().testFunction();

OR you could add a wrapper function in RTSUnit that then passes the call up to the datablock eg

function RTSUnitData::testFunction(%this)
{
    echo("I'm in the datablock testfunction");
}

function RTSUnit::testFunction(%this)
{
  echo("RTSUnit function passing call to datablock namespace");
  %this.getDataBlock().testFunction();
}
#2
04/15/2006 (7:29 am)
Ah I see, I thought that when a object was assigned a datablock it inherited all of its functions. Thanks that has solved alot of unexplained errors I have had.