Question about referencing objects by name
by Cramer · in Torque Game Engine · 08/24/2004 (7:33 am) · 0 replies
Basically we have some items in game we'd like to reference by name:
In our mission file we have:
new Item() {
position = "269.224 -785.538 172.529";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "Pickup_1";
collideable = "0";
static = "1";
rotate = "1";
};
And elsewhere we have:
datablock ItemData( Pickup_1 )
{
category = "Pickups";
shapeFile = "~/data/shapes/Pickup/mapped_pickup.dts";
};
function ItemData::create( %data )
{
%obj = new Item()
{
dataBlock = %data;
rotate = true;
static = true;
};
return %obj;
}
function Pickup_1::onCollision( %this, %obj, %col )
{
%obj.setHidden(true);
factorPickup("message_1.png");
}
That didn't work at all so I figure it's supposed to be like this in the mission file:
new Item(Pickup_1) {
position = "269.224 -785.538 172.529";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "Pickup_1";
collideable = "0";
static = "1";
rotate = "1";
};
Once I do that I can now reference it by:
%getID = nameToID("MissionGroup/Pickup_1");
and get the ID and do what I want with it then other then hardcoding in an ID...
is that correct?
The reason I ask is, the in-game gui won't let you name an item with a datablock included. if we try, it empties out our datablock field and that's not a good thing :) I'm wondering if we're supposed to apply naming in the datablock item itself but we haven't had any luck doing that or if we should be doing nothing with the datablock for these particular items and we're doing this all wrong :)
I'm new at this but getting the hang of it one step at a time, any info would be appreciated.
thnx
In our mission file we have:
new Item() {
position = "269.224 -785.538 172.529";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "Pickup_1";
collideable = "0";
static = "1";
rotate = "1";
};
And elsewhere we have:
datablock ItemData( Pickup_1 )
{
category = "Pickups";
shapeFile = "~/data/shapes/Pickup/mapped_pickup.dts";
};
function ItemData::create( %data )
{
%obj = new Item()
{
dataBlock = %data;
rotate = true;
static = true;
};
return %obj;
}
function Pickup_1::onCollision( %this, %obj, %col )
{
%obj.setHidden(true);
factorPickup("message_1.png");
}
That didn't work at all so I figure it's supposed to be like this in the mission file:
new Item(Pickup_1) {
position = "269.224 -785.538 172.529";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "Pickup_1";
collideable = "0";
static = "1";
rotate = "1";
};
Once I do that I can now reference it by:
%getID = nameToID("MissionGroup/Pickup_1");
and get the ID and do what I want with it then other then hardcoding in an ID...
is that correct?
The reason I ask is, the in-game gui won't let you name an item with a datablock included. if we try, it empties out our datablock field and that's not a good thing :) I'm wondering if we're supposed to apply naming in the datablock item itself but we haven't had any luck doing that or if we should be doing nothing with the datablock for these particular items and we're doing this all wrong :)
I'm new at this but getting the hang of it one step at a time, any info would be appreciated.
thnx
About the author