Game Development Community

Unable to find function ItemData::create

by Yannick Lahay · in Torque Game Engine · 04/30/2007 (5:02 am) · 6 replies

Hello!

I've created an ItemData datablock, and when I want to include that item to my game using the World Editor Creator, in the console it says: Unable to find function ItemDate::create. So nothing is created...

Did I miss something?

Thanks for your help :)

#1
04/30/2007 (5:11 am)
You need to have a function like this somewhere:
//-----------------------------------------------------------------------------
// Hook into the mission editor.

function ItemData::create(%data)
{
   // The mission editor invokes this method when it wants to create
   // an object of the given datablock type.  For the mission editor
   // we always create "static" re-spawnable rotating objects.
   %obj = new Item() {
      dataBlock = %data;
      static = true;
      rotate = true;
   };
   return %obj;
}
By default it's located in server/scripts/item.cs
#2
04/30/2007 (5:19 am)
Thank you very much Tim!

I'll add this code in editor.cs ^^
#3
04/30/2007 (12:30 pm)
//-----------------------------------------------------------------------------// Hook into the mission editor.

function ItemData::create(%newObj)
{
// The mission editor invokes this method when it wants to create
// an object of the given datablock type. For the mission editor
// we always create "static" re-spawnable rotating objects.

%obj = new Item()
{
dataBlock = NewItemName;
static = true;
rotate = true;
};
return %obj;
}

// Then make a datablock file for it....
datablock ItemData(NewItemName)
{

// Basic Item properties
emap = false;
directUse = 0;
modes = 1;
image = YourImage;
imageNum = 1;

// Mission editor category
category = "Items";


className = "Weapon"; // whatever it is

// Basic Item properties
shapeFile = "~/client/data/shapes/items/platform.dts"; //Your ShapeFile
mass = 1;
elasticity = 0.2;
friction = 0.6;

};
#4
04/30/2007 (11:08 pm)
And, of course, static and rotate don't have to be set to true...
#5
05/01/2007 (10:12 am)
Thanks for your help ^^

I've got another question relating to the creation of an item.
I'd like to execute code when the item is created.

Here is what I've written for testing purpose:
function myItem::onCreate(%this, %obj)
{
   // we get its Transform coordinates 
   %get = %obj.getTransform();
   %px = getword(%get,0);
   %py = getword(%get,1);
   %pz = getword(%get,2);
   %rx = getword(%get,3);
   %ry = getword(%get,4);
   %rz = getword(%get,5);
   
   echo("Position:" SPC %px SPC %py SPC %pz);
   echo("Rotation:" SPC %rx SPC %ry SPC %rz);
}

When the code is executed, nothing happens. And there is no error.
#6
05/01/2007 (10:17 am)
It's ok, I've used the onAdd method and it works now :)