Create new objects by console command
by Dane McGreevy · in Torque Game Engine · 03/12/2006 (5:31 pm) · 7 replies
Hi All,
I am just wondering whether we can create objects, say trees, hourses, etc, etc, simply by means of typing some command in the console as well as setting their DTS and positions, rather than deploying the .cs file? I did find some clue while going through the toturial. When I followed up the tutorial writing the command into the console to create some objects, i was lost! :(
Here comes an example as below:
*datablock StaticShapeData(MyFirstDataBlock) {shapeFile = "~/data/shapes/buildings/house_10.dts"; junkvar = "hellohouse"; };*
I put it as one single line in the console, yet ending up with an error response:
* (0): preload failed for myobj1: ShapeBaseData: Couldn't load shape "~/data/shapes/buildings/house_10.dts".*
I am pretty sure the directory of the DTS file is correct.
I was then doing another try by using *new* key word, as below:
*$myNewObj = new StaticShape {};*
Then it poped up an error, * (0): Register object failed for object (null) of class StaticShape.*. Was there anything to do with registering the object process? But when I used *$newObj = new SimObject {};*, it was no problem at all and I could find the new object I created right up in the World Inspector GUI! I really don't like simObject as it has no position information associated with the DTS. How can I figure it out?
All in all, how can we create objects and set properties only right within the console line? Best thanks in advance!!!
I am just wondering whether we can create objects, say trees, hourses, etc, etc, simply by means of typing some command in the console as well as setting their DTS and positions, rather than deploying the .cs file? I did find some clue while going through the toturial. When I followed up the tutorial writing the command into the console to create some objects, i was lost! :(
Here comes an example as below:
*datablock StaticShapeData(MyFirstDataBlock) {shapeFile = "~/data/shapes/buildings/house_10.dts"; junkvar = "hellohouse"; };*
I put it as one single line in the console, yet ending up with an error response:
* (0): preload failed for myobj1: ShapeBaseData: Couldn't load shape "~/data/shapes/buildings/house_10.dts".*
I am pretty sure the directory of the DTS file is correct.
I was then doing another try by using *new* key word, as below:
*$myNewObj = new StaticShape {};*
Then it poped up an error, * (0): Register object failed for object (null) of class StaticShape.*. Was there anything to do with registering the object process? But when I used *$newObj = new SimObject {};*, it was no problem at all and I could find the new object I created right up in the World Inspector GUI! I really don't like simObject as it has no position information associated with the DTS. How can I figure it out?
All in all, how can we create objects and set properties only right within the console line? Best thanks in advance!!!
#2
I will go for it immediately! Thank you.
03/12/2006 (5:47 pm)
WOW. Peter, i am quite sure that this is the quickest response I have ever seen in the TGE community! :P I will go for it immediately! Thank you.
#3
What I did firstly is I made a brand new .cs file and put *exec it* right into ~/server/scripts/game.cs so that i hoped to get it compiled and loaded up together with other required objects. And it's been tested NICE! Compiling and loading went great.
The only thing I didn't want to occur was the *position* field was filled with *0 0 0* rather than what I expected to be the player's position. When I changed position in the function to be some specific coordinates, it was then placed onto the right position as I could check it up on the World Inspector GUI.
So, I am guessing the blurry point is *ServerConnection.player.getPosition*. Am I right at this point? Big thanks!
03/12/2006 (6:43 pm)
Hi Peter, I am back from testing.What I did firstly is I made a brand new .cs file and put *exec it* right into ~/server/scripts/game.cs so that i hoped to get it compiled and loaded up together with other required objects. And it's been tested NICE! Compiling and loading went great.
The only thing I didn't want to occur was the *position* field was filled with *0 0 0* rather than what I expected to be the player's position. When I changed position in the function to be some specific coordinates, it was then placed onto the right position as I could check it up on the World Inspector GUI.
So, I am guessing the blurry point is *ServerConnection.player.getPosition*. Am I right at this point? Big thanks!
#4
03/12/2006 (7:07 pm)
Try ServerConnection.getControlObject().getPosition();
#5
*position = $player.getPosition();*, and it's a success. :p
Can you point me on how ServerConnection works? Does it actually pass the command to server to request the current position of controlled object? Can each client call this function to manually make new objs, provided within server- a multiple clients environment?
Thank you for your pointer.
03/12/2006 (7:24 pm)
Yeah. It worked nicely! Thank you, Peter! I also did another minor change: *position = $player.getPosition();*, and it's a success. :p
Can you point me on how ServerConnection works? Does it actually pass the command to server to request the current position of controlled object? Can each client call this function to manually make new objs, provided within server- a multiple clients environment?
Thank you for your pointer.
#6
This come will send the command to make a new house to the server. Whatever you set as the command in commandToServer will be the name of the function it calls (with serverCmd prepended). So in this case createHouse is the command, so it will call the function serverCmdCreateHouse on the server. It will automaticly add the variables you pass.
-Pete
03/12/2006 (7:52 pm)
Any time work is done in the game (something created, moved, any changes) it is done on the server. So for this command to work in multiplayer you would need to use commandToServer.//Place this code somewhere in a client script
function makeHouse(%houseNumber, %title)
{
commandToServer('createHouse', %houseNumber, %title);
}
// This code can go in server/scripts/commands.cs
function serverCmdCreateHouse(%client, %houseNumber, %title)
{
new TSStatic()
{
shapeFile = "~/data/shapes/buildings/house_" @ %houseNumber @ ".dts";
position =%client.getControlObject().getPosition();
title = %title;
};
}This come will send the command to make a new house to the server. Whatever you set as the command in commandToServer will be the name of the function it calls (with serverCmd prepended). So in this case createHouse is the command, so it will call the function serverCmdCreateHouse on the server. It will automaticly add the variables you pass.
-Pete
#7
Still some blurry point coming up: in your codes, client side isn't seemingly sending %client to sever side, is it? My guess is the server side can automatically cleverly identify the client player where the command comes.
Moving on, I am now wondering the possible automated way of creating a huge stack of trees or buildings from within console. Basically, what I hope to get to is that we don't actually need to load the entire mission file to create just a few newly developed objects as it normally takes a while to load the mission file, so that we can only type some commands to console to create or delete many objects at a time associated with accurate positions.
My idea: can we just make a new .cs file in which we write a series of *makeHouse* functions, and simply run *exec()* this cs in console? I have just tried this method, but ended up with *Missing file: ~/starter.fps/client/scripts/blabla.cs!* Was I on the wrong track? I am trying my best to be a good torque scripter...
Any nice idea? Thank you very much!
03/12/2006 (9:17 pm)
It turned out a success again (after I changed "shapeFile" to "shapeName" :p). Greatly thankful for the clarity, Peter! I think I am getting clearer on Torque's networking as to which the tutorial does't come very handy to me. Still some blurry point coming up: in your codes, client side isn't seemingly sending %client to sever side, is it? My guess is the server side can automatically cleverly identify the client player where the command comes.
Moving on, I am now wondering the possible automated way of creating a huge stack of trees or buildings from within console. Basically, what I hope to get to is that we don't actually need to load the entire mission file to create just a few newly developed objects as it normally takes a while to load the mission file, so that we can only type some commands to console to create or delete many objects at a time associated with accurate positions.
My idea: can we just make a new .cs file in which we write a series of *makeHouse* functions, and simply run *exec()* this cs in console? I have just tried this method, but ended up with *Missing file: ~/starter.fps/client/scripts/blabla.cs!* Was I on the wrong track? I am trying my best to be a good torque scripter...
Any nice idea? Thank you very much!
Torque 3D Owner Peter Simard
Default Studio Name
function makeHouse(%houseNumber, %title) { new TSStatic() { shapeFile = "~/data/shapes/buildings/house_" @ %houseNumber @ ".dts"; position = ServerConnection.player.getPosition; title = %title; }; }Then you can call it from the console:
I havent tested the code but it should give you a good start