Game Development Community

Can't get datablock for object

by ChrisG · in Torque Game Engine · 06/16/2007 (5:20 pm) · 2 replies

I've implemented Mark Holcomb Scripted Doors resource at got it working OK.

Now I'm trying to create an elevator and I've made a button to summon the elevator. At the moment all I'm trying to do if make the button light up when it's pressed.

To do this I'm using the interact function that was part of the Scripted Doors resource. When the object is interacted with it's shapefile should change to one with a lit button. (This might not be the 'best' way to do it but I wanted to see if it would work.)

The problem is that when I try to interact with the button object nothing happens and I get the following error...

starter.fps/server/scripts/interact.cs (27): Unknown command getDataBlock.
Object (2788) InteriorInstance -> SceneObject -> NetObject -> SimObject
starter.jpf/server/scripts/interact.cs (27): Unable to find object: '' attempting to call function 'interact'


I've created the following datablock and interact function based on the one from the door resource

// This script allows player to interact with the lift button
// ie. the one outside the left that summons the lift

// when the button is pressed (interected with):
// - the shape file is swapped with the button On shape file
// - the elevator server object is notified that the elevator was summoned to this floor

// ------------------------------------------------------------
//This is the outside lift button
datablock StaticShapeData(OutsideLiftBtn)
{
  // The category variable determines where the item
  // shows up in the mission editor's creator tree.
  category = "Elevator";

	// this is the initial shape file used for lift button (off state)
	shapeFile = "~/data/shapes/office/elevator/outsidebtnoff.dts";

	// shape file when in on status
	onShapeFile = "~/data/shapes/office/elevator/outsidebtnon.dts";
	offShapeFile  = "~/data/shapes/office/elevator/outsidebtnoff.dts";

	// This holds the state of the switch, used for toggling.
	isBtnOn = false;   
};


// ------------------------------------------------------------
//This function is called whenever the client presses the 'use' key
//within the set distance.
// ACCEPTS: ???
//					the lift btn object that was interacted with
//					???
function OutsideLiftBtn::interact(%this, %obj, %client)
{
	// if the button is off then turn button on
	if (!%obj.isBtnOn)
	{
		%obj.isBtnOn = true;
		%obj.shapeFile = %obj.onShapeFile;	
	}
}


I also add the exec line to the onServerCreated() in game.cs to include the file with this datablock.

The dts object has 1 collision mesh and the object bounds.

I'm still pretty new to Torque Script and I'm probably missing something fairly obvious - any help would be appreciated.

thanx

#1
06/18/2007 (4:17 am)
Got the interact function to give a response - the problem turned out to be that the object was too small (.12 x .12 x .1m). I increased the size of the bounds and collision mesh to .3 x 1 x 1.2 and it fixed the problem.

Now I've just discovered that you can't swap the shapeFile dynamically so it's time to investigate IFLs
#2
06/18/2007 (4:50 am)
Woohoo! this is what finally worked. I swapped the datablock...

// This script allows player to interact with the lift button
// ie. the one outside the left that summons the lift

// when the button is pressed (interected with):
// - the datablock is swapped with the on datablock
// - the elevator server object is notified that the elevator was summoned to this floor

// ------------------------------------------------------------
//This is the outside lift button in the off state
datablock StaticShapeData(OutsideLiftBtn)
{
  // The category variable determines where the item
  // shows up in the mission editor's creator tree.
  shapeFile = "~/data/shapes/office/elevator/outsidebtnoff.dts";
  category = "Elevator";
	isBtnOn = false;   
};

// ------------------------------------------------------------
//This is the outside lift button in the on state
datablock StaticShapeData(OutsideLiftBtnOn)
{
	category = "Elevator";
	shapeFile = "~/data/shapes/office/elevator/outsidebtnon.dts";
	isBtnOn = true;   
};


// ------------------------------------------------------------
//This function is called whenever the client presses the 'use' key
//within the set distance.
// ACCEPTS: ???
//					the lift btn object that was interacted with
//					???
function OutsideLiftBtn::interact(%this, %obj, %client)
{
	echo("Changing OutsideLiftBtn datablock to OutsideLiftBtnOn");	
	%obj.setDataBlock( "OutsideLiftBtnOn" );
}