Game Development Community

Inheriting the AbstractSwitcher Template?

by Chad Kilgore · in Game Mechanics Kit · 12/19/2009 (12:24 pm) · 4 replies

I am trying to create a new Switcher type, called Grammophone. But when I add the object, the object does not have any of the AbstractSwitcher parameters, such as 'usable'.

datablock StaticShapeData(Grammophone)
{
	class = "SwitcherData";
   shapeFile = "art/shapes/lever/lever.dts";
    
   position = "0 0 0";
	Scale = "1 1 1";
	emap = true;
	receiveSunLight = "1";
	
	openAnimation = "Switch_on";
	closeAnimation = "Switch_off";
	closeAnimationReverse = false;
	
	openSnd = sndGrammophone;
	closeSnd = sndGrammophone;
};

//-----------------------------------------------------------------------------
// for Game Mechanics Editor
//-----------------------------------------------------------------------------

ActivatePackage(TemplateFunctions);
   inheritTemplate("Grammophone", "AbstractSwitcher");
   registerTemplate("Grammophone", "Switches", "SwitcherData::create(Grammophone);");
DeactivatePackage(TemplateFunctions);

Does anybody have any ideas what I am doing wrong?

#1
12/19/2009 (5:15 pm)
I just tried your script and saw no problem with the parameters. All parameters, including "usuable", were present in the editor. The scripting looks fine. Try looking in the console log for any errors or warnings.
#2
12/21/2009 (11:55 am)
I figured it out. I was trying to divide it into the art/datablock and scripts/server. The scripts did not yet initialize by the time the datablock was built, thus the template did not yet exist. I rearranged some code and it works. Thank you very much for your help.
#3
12/21/2009 (2:17 pm)
hey Chad,
can you tell us what code you re-aranged?
I had a simmilar thing happen to me...
#4
12/21/2009 (8:39 pm)
In scripts/sever/scriptExec.cs:
// Load GMK
exec("./logickingMechanics/logickingMechanics.cs");

// Load Objects
exec("./objects/grammophone.cs");

In scripts/server/objects/grammophone.cs (where the datablocks script is executed):
exec("art/datablocks/objects/grammophone.cs");

//-----------------------------------------------------------------------------

function Grammophone::onAdd(%this)
{
...
}

function cGrammophone::init(%this)
{
	Switcher::init(%this);
}
...


For additional functionality, I added to scripts/server/logickingMechanics/switcher.cs:
function SwitcherData::create_defClass(%data, %class)
{
   if (%class $= "")
   {
      echo("***** DEBUG: Defining SwitcherData class to be Switcher");
      %class = "Switcher";
   }
   
	%obj = new StaticShape() {
		class = %class;
		dataBlock = %data;
	};
	
	return %obj;
}

This function allows you to define the class of the object when you register the template.