Game Development Community

Datablock creation from Triggers problem

by DavidF215 · in Torque Game Engine · 10/02/2006 (7:45 pm) · 0 replies

I've been trying to figure this problem out for too long, and I am just not figuring it out. It is probably simple, but I am missing it. I have tried a variety of methods, but I have been unsuccessful. I haven't found any forum posts related to ItemData coding, though I might have overlooked something.

What I am simply trying to do is spawn a new ItemData type when the player is on a Trigger for a period of time.

Here a clip of the filename "resources.cs" (located in .\server\scripts) that contains the datablock definition of a new ItemData type:

datablock ItemData( RawIron )
{
category = "Resources";
shapeFile = "~/data/shapes/superbomb/superbomb.dts"; //Temporary Object placeholder
};

function ItemData::spawn(%this, %blk, %spawnPoint)
{
%p = new Item()
{
dataBlock = %blk //RawIron type;
static=false;
};

%p.setTransform( %spawnPoint );
return %p;
}

The "spawn" function is what I am calling from an onTickTrigger function to spawn the RawIron Item dynamically. Here is the code from triggers.cs that I am using to try and call the "spawn" function:

function mineOreTrigger::onTickTrigger(%this,%trigger)
{
if(%this.objectID.getClassName() $="Player"){
%obj=ItemData::spawn(RawIron,%this.objectID.getTransform()); //HERE IS THE SPAWN CALL
MissionCleanup.add(%obj);
echo ("You have chiselled out a chunk of rock containing raw iron. Item #:" @ %obj); //Debug code
}
Parent::onTickTrigger(%this,%trigger);
}

The line marked "Here is the spawn call" is where I am attempting to create a RawIron ItemData type. This is the Conscole script error that I keep getting:

Object 'RawIron' is not a member of the 'GameBaseData' data block class
[then I get 'unable to find object' errors]

The trigger itself works fine, but it won't create the object. I have even moved the 'exec ("./triggers.cs");' command in the server\scripts\game.cs file to come after a 'exec("./resources.cs");' command.

The "spawn" function would also be used for creating ItemData types if another Item or [PlayerBody] object was destroyed.

Any ideas or links to related posts would be helpful.