Game Development Community

Create() called by editor.cs for creating new datablocks

by CSUMB (#0032) · in Torque Game Engine · 02/21/2005 (7:39 pm) · 2 replies

Hi,

I have a quick question. I'm looking at the code-sample tutorial for
creating a dataItem and colliding with it (superbomb example).

I notice that when you implement the method "create()" it is associated
with the datablock, and not the superbomb. (see below)

Why can't I assosicate "create" with SuperBomb. When I try this
I can an error message that the "Editor.cs" unable to find ItemData.create().

If I can't associate this with "SuperBomb" instead of ItemData, then
how can I have more than 1 type of ItemData that I can insert into
mission via the editor?


-Michael

------------------------------------------------------------------------------------

datablock ItemData( SuperBomb )
{

category = "Bombs";
shapeFile = "~/data/shapes/superbomb/superbomb.dts";
};



function ItemData::create( %data )
{
echo( "ItemData::create for SuperBomb called" );

%obj = new Item()
{
dataBlock = %data;

};
}

#1
02/22/2005 (1:03 pm)
The create() function isn't a datablock function. It's a datablock class space function, or something like that. (or "the mother of all datablocks").

The %data in ItemData::create(%data) is actually a reference to your newly born datablock (that has just spawned off ItemData).

To make the bomb appear in the mission editor, you only need to use the "category" field. Type something in there and the datablock will be listed inside the "Shapes" category in the mission editor.

In your case, your superBomb is in shapes > Bombs in the mission editor.
#2
03/20/2007 (5:51 pm)
Sorry to bring this back from the dead, but I just want to be clear about something.

when the "Editor" calls create(), how does it know what to create exactly?

Or in other words, does the editor pass the name of whatever you clicked on in the creator
panel to the create function?

If not, how does it know which item to create?

Thanks! and sorry for bringing this thread back...