Game Development Community

Getting something to happen all the time....

by Simon Goodchild · in Torque Game Engine · 09/14/2007 (5:28 am) · 2 replies

Hi all, new to TGE so hope this is the right place to ask!

I want to have on the screen which direction the player is heading in degrees (eg, "You are heading: 210 degrees") and helpful replies from Peter Simard to posts elsewhere have given me the code, but I've still got a newbie question!!

When do I put the code that sets up the schedule to run every (say, 1/10th of a second), and where do I put the functions that it calls?

I've got so far :

function getAngleofVector(%vec)
{ ... gets the heading ... }

and

function Player::onAdd(%this)
{
%this.schedule(100, "updateHeading");
}

function Player::updateHeading(%this)
{
%heading = getAngleofVector(%this.getForwardVector());
myGui.setText("Facing angle:" @ %heading);
%this.schedule(100, "updateHeading");
}

But I'm not clear as to whether the above two are new functions, or additions to existing functions (or to be honest which files they would/should be in).

So I'm trying to simplify things and just add a schedule somewhere which will run as long as the player is in the mission to update some text on a GuiControl (my text control is called "heading" btw).

Any help on either the heading bit, or even the simple bit in the sentence above(!), really appreciated.

Thank you! Once I've understood this, so much more will be open to me (and lack of sleep no doubt!)

#1
09/14/2007 (8:55 am)
Ok, making some progress (Crickey, this is like starting to program all over again!)

I found that if I edit server/player.cs and put the following function in at the bottom:

function PlayerBody::updateHeading(%this)
{
   guiCompassHeading.setText("HERE!");
   schedule(100, 0, PlayerBody::updateHeading, %this);
}

and add this line to PlayerBody::onAdd

function PlayerBody::onAdd(%this,%obj)
{
   // Called when the PlayerData datablock is first 'read' by the engine (executable)
   schedule(100, 0, PlayerBody::updateHeading, %this);
}

that the client Gui Control changes when the player enters. No idea if the schedule inside the updateHeading function is working, but going to try that next!

Is this right?!?! :)
#2
09/14/2007 (2:52 pm)
Ok - not quite right, not really working, but I've had a bit more success elsewhere. This is now my current headache, and so I've caried on this thread as part of my experience on this thread instead.