How to record character trajectory information?
by Ean Huddleston · in Torque Game Engine · 01/10/2007 (2:39 pm) · 3 replies
I'd like to do something that with TGE that I doubt is often done. I'm creating a virtual reality psychology experiment (I'm a grad student) in which human subjects will move about, finding little objects, and later try to remember where they found them. What I'd like to do is record in a file information about the path that a subject took while exploring the environment (the game level). Does anybody have any suggestions on what might be the easiest way to do this? Is it possible to create a function in script that is automatically called every x milliseconds, which would then write the coordinates of the subject's current location to a file? It wouldn't have to be *exactly* every x milliseconds, just frequently enough for me to track their movements with decent spatial resolution.
Thanks for any ideas you've got!
Thanks for any ideas you've got!
#2
01/12/2007 (10:28 am)
@Michael, thanks so much for the detailed example/code! That will most definitely get me going in the right direction.

Employee Michael Perry
ZombieShortbus
In starter.fps/server/scripts/player.cs:
// At the end of the file function StartRecordingPlayerPos() { // Start recording the player's position $RecordingPlayer = true; commandToServer('StartRecordingPlayer'); // every 2000 ms, try to record player's position schedule(2000, 0, Record); } function Record() { // Call the server command (which is where the real functionality is) commandToServer('RecordPosition'); // Repeat function in 2000 ms $RecordingThread = schedule(2000, 0, Record); } function StopRecordingPlayerPos() { // If the schedule exists to record the position again // cancel it. if(isEventPending($RecordedLocation)) cancel($RecordingThread); // Stop recording $RecordingPlayer = false; commandToServer('StopRecordingPlayer'); } function SaveRecordedInfo() { // Save the positions to text file commandToServer('SaveRecord'); }In starter.fps/server/scripts/commands.cs:
// At the end of the file function serverCmdStartRecordingPlayer(%client) { if(isObject(%client.player)) { $RecordedLocation[0] = getWords(%client.player.getTransform(), 0, 2); $CurrentRecordIndex = 0; commandToServer('RecordPlayerPosition', %client); } } function serverCmdRecordPosition(%client) { %newLocation = getWords(%client.player.getTransform(), 0, 2); if($RecordedLocation[$CurrentRecordIndex] $= %newLocation) { echo("Doing nothing"); } else { $CurrentRecordIndex++; $RecordedLocation[$CurrentRecordIndex] = %newLocation; echo($RecordedLocation); } } function serverCmdSaveRecord(%client) { %writer = new FileObject(MyWriter); MyWriter.openForWrite("starter.fps/data/recordedInformation.txt"); for(%i = 0; %i < $CurrentRecordIndex; %i++) { MyWriter.writeLine($RecordedLocation[%i]); } MyWriter.close(); }The formatting of the outputted file is a little wonky, but it's a good start for you.
*EDIT* Fixed formatting of text file, removed unnecessary variable, made the ouput file cleaner.
Sample output file