Need help to access game state info
by EricCartman · in Technical Issues · 01/31/2005 (10:57 pm) · 8 replies
Hi,
I am a newbie to torque, and I would like to write some script that get the game state, i.e. position of all players, and names, weapon list in the current game. So far I have only been able to figure out how to create an object and get its id and move it around using script.
also, does torque script have file access functions like fopen, fprintf extra?
Thanks
I am a newbie to torque, and I would like to write some script that get the game state, i.e. position of all players, and names, weapon list in the current game. So far I have only been able to figure out how to create an object and get its id and move it around using script.
also, does torque script have file access functions like fopen, fprintf extra?
Thanks
#2
02/01/2005 (6:50 am)
Thanks for the reply, but how do I programatically go through all the objects in the world?
#3
Most likely the MissionGroup - but I'm not 100% sure
Code example for iteration can be seen on the server side script for the messageAll() method
02/01/2005 (7:41 am)
If you do this on the server side, then I think all objects are in the one of the global variables.Most likely the MissionGroup - but I'm not 100% sure
Code example for iteration can be seen on the server side script for the messageAll() method
#4
%player=%client.player;
%player.dump();
how come this doesn't work? It keeps telling me "unable to find object"?
Thanks
02/02/2005 (2:52 pm)
I have tried the following:%player=%client.player;
%player.dump();
how come this doesn't work? It keeps telling me "unable to find object"?
Thanks
#5
When you join a server(your own) you can open the console and scroll back till you find this line...
CADD: 1430 local
The number may not be the same(1430) but that number is your client ID on the server. If you were to type into the console...
1430.dump();
it would dump all the client related variables and functions to your console. You can then examine the objects current state and the functions you can use to manipulate it. The next thing you can do is to find out what your "player" object ID is by typing into the console...
echo(1430.player);
Which most likely would dump the number 1432 to the console because the server would create a camera object for you to see with when you log in which would make the camera ID 1431 and then it will create you a player to play with which would be 1432.
Now, to find out what the state of your player is and what functions you can use to manipulate it with you can do one of TWO things, you can either type into your console...
1432.dump();
like you did with your client ID, or you can skip finding the player ID at all and just use your client ID number like this...
1430.player.dump();
Likewise you can figure out all your camera states and functions by using either of these two(assuming you have the numbers correct)...
1431.dump();
or
1430.camera.dump();
You cannot enter %client.player.dump(); into your console because the engine has no clue what %client is. The proper place to find such info would be a function like...
function GameConnection::doFoo(%client)
{
// do stuff
}
which would allow you to use the %client variable to spawn the other information. An example would be...
function GameConnection::doFoo(%client)
{
%player = %client.player;
%player.doSomethingHere();
}
or to simplify you can just directly manipulate the player like so...
function GameConnection::doFoo(%client)
{
%client.player.doSomethingHere();
}
02/03/2005 (12:24 am)
EricWhen you join a server(your own) you can open the console and scroll back till you find this line...
CADD: 1430 local
The number may not be the same(1430) but that number is your client ID on the server. If you were to type into the console...
1430.dump();
it would dump all the client related variables and functions to your console. You can then examine the objects current state and the functions you can use to manipulate it. The next thing you can do is to find out what your "player" object ID is by typing into the console...
echo(1430.player);
Which most likely would dump the number 1432 to the console because the server would create a camera object for you to see with when you log in which would make the camera ID 1431 and then it will create you a player to play with which would be 1432.
Now, to find out what the state of your player is and what functions you can use to manipulate it with you can do one of TWO things, you can either type into your console...
1432.dump();
like you did with your client ID, or you can skip finding the player ID at all and just use your client ID number like this...
1430.player.dump();
Likewise you can figure out all your camera states and functions by using either of these two(assuming you have the numbers correct)...
1431.dump();
or
1430.camera.dump();
You cannot enter %client.player.dump(); into your console because the engine has no clue what %client is. The proper place to find such info would be a function like...
function GameConnection::doFoo(%client)
{
// do stuff
}
which would allow you to use the %client variable to spawn the other information. An example would be...
function GameConnection::doFoo(%client)
{
%player = %client.player;
%player.doSomethingHere();
}
or to simplify you can just directly manipulate the player like so...
function GameConnection::doFoo(%client)
{
%client.player.doSomethingHere();
}
#6
But, my question still remains: "how do you loop though all objects( including players, ammo, weapons, vechiles) in the current game, get their id and dump everyone of them's info?"
I thought I could do what this said:
http://tork.beffy.de/tutorials/littlehelpers/snippits.php#004
but apperantly, I am not suppose to use it the way I thought...
Please advice
02/03/2005 (12:33 am)
Thanks gonzo for the detailed explanation.But, my question still remains: "how do you loop though all objects( including players, ammo, weapons, vechiles) in the current game, get their id and dump everyone of them's info?"
I thought I could do what this said:
http://tork.beffy.de/tutorials/littlehelpers/snippits.php#004
but apperantly, I am not suppose to use it the way I thought...
Please advice
#7
Open your console and type in...
tree();
And a double GUI will pop up with every object currently existing in your TGE load. You can browse through the tree and click on each object to see it's current state and variable settings. Then if you want the functions you can get the objects ID from the tree and open your console and dump the info. Using code to do it would be complicated and would risk crashing if you messed with the wrong stuff. If you would like to view everything that is loaded into MissionGroup and MissionCleanup in a nicely formatted text file, you could type into the console...
MissionGroup.save("./MissionGroup.cs");
and
MissionCleanup.save("./MissionCleanup.cs");
This will save both groups into .cs files in a fashion exactly like saving a mission does and you can review the state of everything that is there in a more comfortable setting. This will NOT export the functions for each item though. You would still have to do that manually.
Or I guess you could use this...(UNTESTED, WROTE IT JUST NOW)
Make sure that gets exec'ed in your scripts and then you can load up a mission and open your console and type in...
dumpThatShiznit();
and it will dump everything in those groups into your log file. Then you can close the game, change the console.log to DumpedFunctions.log so you can save them for later reference.
02/03/2005 (1:01 am)
Since you are new, instead of going through a bunch of code, I would use the tree.Open your console and type in...
tree();
And a double GUI will pop up with every object currently existing in your TGE load. You can browse through the tree and click on each object to see it's current state and variable settings. Then if you want the functions you can get the objects ID from the tree and open your console and dump the info. Using code to do it would be complicated and would risk crashing if you messed with the wrong stuff. If you would like to view everything that is loaded into MissionGroup and MissionCleanup in a nicely formatted text file, you could type into the console...
MissionGroup.save("./MissionGroup.cs");
and
MissionCleanup.save("./MissionCleanup.cs");
This will save both groups into .cs files in a fashion exactly like saving a mission does and you can review the state of everything that is there in a more comfortable setting. This will NOT export the functions for each item though. You would still have to do that manually.
Or I guess you could use this...(UNTESTED, WROTE IT JUST NOW)
function dumpThatShiznit()
{
MissionGroup.save("./MissionGroup.cs");
%count = MissionGroup.getCount() - 1;
for(%i=0;%i < %count;%i++)
{
MissionGroup.getObject(%i).dump();
}
MissionCleanup.save("./MissionCleanup.cs");
%count = MissionCleanup.getCount() - 1;
for(%i=0;%i < %count;%i++)
{
MissionCleanup.getObject(%i).dump();
}
error("Gonzo Rocks!");
}Make sure that gets exec'ed in your scripts and then you can load up a mission and open your console and type in...
dumpThatShiznit();
and it will dump everything in those groups into your log file. Then you can close the game, change the console.log to DumpedFunctions.log so you can save them for later reference.
#8
02/03/2005 (3:12 pm)
Excellent. Thanks Gonzo. You rock!
Torque Owner Thomas \"Man of Ice\" Lund
Open a console and type
%id of object.dump();
That will give you the entire list of variables and methods for that object.
E.g. getPosition(), getTransforms(), getShapeName() etc.