How do you deploy a static object
by Nic Biondi · in Torque Game Engine · 01/23/2004 (12:50 am) · 6 replies
I am having the worst trouble creating a static object in-game. It seems like a reletively simple task. I hope that response to this topic will shed light on the matter for me and others who read it.
Set up:
I have the flagpole.cs and flagpole.dts available from the toutorials on the getting started page here -> http://www.garagegames.com/docs/torque.sdk/. I also have main.cs exec function in place to load the flag into the console and subsequently into the editor. I can place the flag on the ground and everything seems to be ok.
I have mapped a key to a server command as in the toutorial, so I can press a button (t) and get a echo on the screen: messageClient(%client, 'MsgTutorial', '\c0I wish this was a flag');
Problem:
The issue I am having is trying to spawn a static object at the click of the button. I have tried: %item = new StaticShapeData(Flag){}. but it does not seem to work.
please advise
Set up:
I have the flagpole.cs and flagpole.dts available from the toutorials on the getting started page here -> http://www.garagegames.com/docs/torque.sdk/. I also have main.cs exec function in place to load the flag into the console and subsequently into the editor. I can place the flag on the ground and everything seems to be ok.
I have mapped a key to a server command as in the toutorial, so I can press a button (t) and get a echo on the screen: messageClient(%client, 'MsgTutorial', '\c0I wish this was a flag');
Problem:
The issue I am having is trying to spawn a static object at the click of the button. I have tried: %item = new StaticShapeData(Flag){}. but it does not seem to work.
please advise
#2
I am using this code -->
I can call interact.cs just fine, but I am having problems getting it to diplay an object.
01/23/2004 (6:46 pm)
Thank you for your reply james. I think this gets me on the right track. I am using this code -->
function serverCmdinteract(%client)
{
%item = new StaticShapeData(Flag)
{
position = localclientconnection.camera.getPosition();
rotation = "1 0 0 0";
datablock StaticShapeData(Flag)
{
category = "Misc";
shapeFile = "./flagpole.dts";
};
};
%item.setTransform("360 309 217");
}in a file called interact.csI can call interact.cs just fine, but I am having problems getting it to diplay an object.
#3
how do I reference a datablock. I have the toutorials "flagpole.cs" and "flagpole.dts". I dont know how to reference my static shape.
what am I doing wrong here?
01/23/2004 (7:24 pm)
This isnt working either, can you tell me what I am doing wrong?how do I reference a datablock. I have the toutorials "flagpole.cs" and "flagpole.dts". I dont know how to reference my static shape.
what am I doing wrong here?
function serverCmdinteract(%client)
{
flagblock StaticShapeData(Flag)
{
category = "Misc";
shapeFile = "./flagpole.dts";
};
%item = new StaticShapeData(Flag)
{
position = localclientconnection.camera.getPosition();
rotation = "1 0 0 0";
datablock=flagblock;
};
%item.setTransform("360 309 217");
}
#4
The syntax for a new statement is:
new ClassType (ObjectName)
Datablocks are ojects that only hold information, so when you create an object you base it off of that information, but you do not want to create a new dataBlock, but rather a new object. So if you want to create a new item, use %item = new Item () instead of %item = new ItemData (), since the latter is creating a new dataBlock. If you are unsure as to what class name to use, take the class name of the object's datablock, and remove the Data at the end.
(ObjectName) can be any name you want, and can be different for every instance of the the object type. It is an identifier to make it easier to work with the object.
And it's better to not put datablocks inside functions. (It will work, but not always the way you might imagine.) What James was meaning is you put a dataBlock = NameOfTheDataBlockToUse; so the engine knows which datablock contains the information required to create the object.
Of course you do still need the datablock, just not inside the function.
Here's your function with the changes I am referring to.
position = %client.player.getPosition();
01/23/2004 (7:43 pm)
The main problem you are having is coming from your creation method.The syntax for a new statement is:
new ClassType (ObjectName)
Datablocks are ojects that only hold information, so when you create an object you base it off of that information, but you do not want to create a new dataBlock, but rather a new object. So if you want to create a new item, use %item = new Item () instead of %item = new ItemData (), since the latter is creating a new dataBlock. If you are unsure as to what class name to use, take the class name of the object's datablock, and remove the Data at the end.
(ObjectName) can be any name you want, and can be different for every instance of the the object type. It is an identifier to make it easier to work with the object.
And it's better to not put datablocks inside functions. (It will work, but not always the way you might imagine.) What James was meaning is you put a dataBlock = NameOfTheDataBlockToUse; so the engine knows which datablock contains the information required to create the object.
Of course you do still need the datablock, just not inside the function.
Here's your function with the changes I am referring to.
function serverCmdinteract(%client)
{
%item = new StaticShape(Flag)
{
position = localclientconnection.camera.getPosition();
rotation = "1 0 0 0";
datablock = Flag;
};
%item.setTransform("360 309 217");
}position = %client.player.getPosition();
#5
you are geniuses! I love you both, martin especially for the final piece!
01/23/2004 (7:51 pm)
Thank you very much martin, james,you are geniuses! I love you both, martin especially for the final piece!
#6
you are geniuses! I love you both, martin especially for the final piece!
01/23/2004 (8:55 pm)
Thank you very much martin, james,you are geniuses! I love you both, martin especially for the final piece!
Associate James Urquhart
Make sure you are setting the transform of the object so you can see it somewhere in-game.
e.g :
%item = new StaticShapeData(Flag) { position = localclientconnection.camera.getPosition(); rotation = "1 0 0 0"; dataBlock = SomeDataBlock; // Datablock which contains shape info };Or after you created :
%item.setTransform("x y z");Hope that helps.