Any idea why this won't work?
by James Livingston · in Torque Game Engine · 02/07/2006 (8:18 pm) · 6 replies
Trying to figure out how to make some beginning script changes to the starter.racing example. All modifications in the game.cs file.
Just for starters, I want the car to "jump" periodically. I started off by adding some code at the end of the GameConnection::onClientEnterGame function.
function GameConnection::onClientEnterGame(%this)
{
...blah blah blah...
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Client controls the camera by default.
%this.setControlObject(%this.camera);
if(!$Game::Running)
{
// Create a car object.
%thiscar = %this.spawnCar(); //was %this.spawnCar();
schedule(7000,jumper,%thiscar);
echo ("car here = ",%thiscar);
// Orbit the camera around the car
%this.camera.setOrbitMode(%this.car, %this.car.getTransform(), 0.5, 4.5, 4.5);
}
}
First, I couldn't find out how to refer to the car in other portions of the script. %car, %this.car, nothing I tried seemed to be the right object. Should I make it global? The function originally didn't seem to pass it back out, so that other script functions could see it.
Anway, to fix this, I put in %thiscar = %this.spawnCar(), intending to pass the %thiscar to my scheduled jump function below.
scheduled it to run the jumper function in 7 seconds.
Note: At no point, do I see any input at all from the echo ("car here...") statement.
Moving on...
Here is my jumper function:
function jumper(%car)
{
echo ("car = ",%car);
if (isObject(%car))
{
echo(%car.getTransform());
schedule(5000,jumper,%car);
}
}
This function is declared in game.cs, just like the other.
I get no output from the echo statements, nada.
Can anyone explain just what I'm missing here?
I also tried putting in the key mapping to keybind space to a jumper function. No luck there either.
Thanks!
Just for starters, I want the car to "jump" periodically. I started off by adding some code at the end of the GameConnection::onClientEnterGame function.
function GameConnection::onClientEnterGame(%this)
{
...blah blah blah...
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Client controls the camera by default.
%this.setControlObject(%this.camera);
if(!$Game::Running)
{
// Create a car object.
%thiscar = %this.spawnCar(); //was %this.spawnCar();
schedule(7000,jumper,%thiscar);
echo ("car here = ",%thiscar);
// Orbit the camera around the car
%this.camera.setOrbitMode(%this.car, %this.car.getTransform(), 0.5, 4.5, 4.5);
}
}
First, I couldn't find out how to refer to the car in other portions of the script. %car, %this.car, nothing I tried seemed to be the right object. Should I make it global? The function originally didn't seem to pass it back out, so that other script functions could see it.
Anway, to fix this, I put in %thiscar = %this.spawnCar(), intending to pass the %thiscar to my scheduled jump function below.
scheduled it to run the jumper function in 7 seconds.
Note: At no point, do I see any input at all from the echo ("car here...") statement.
Moving on...
Here is my jumper function:
function jumper(%car)
{
echo ("car = ",%car);
if (isObject(%car))
{
echo(%car.getTransform());
schedule(5000,jumper,%car);
}
}
This function is declared in game.cs, just like the other.
I get no output from the echo statements, nada.
Can anyone explain just what I'm missing here?
I also tried putting in the key mapping to keybind space to a jumper function. No luck there either.
Thanks!
About the author
#2
02/07/2006 (11:58 pm)
Btw just to explain... with the schedule command I posted the 0 represents either nothing (in this case) or an object that the schedule will be dependent on, ex. if the object is destroyed then the scheduled funciton will never call, in this case you could place your car there (assuming its a proper object).
#3
02/08/2006 (6:34 am)
Hmmmm...darn, coulda sworn I tried that also. I'll give it a shot, thanks for your responses Matthew!
#4
am I seeign this wrong? do you want to create the car if the game IS NOT Running???
-Ron
02/08/2006 (6:38 am)
Not sure, but the following looks a bit odd to me (granted I have yet to have coffee or food ;) )if(!$Game::Running)
am I seeign this wrong? do you want to create the car if the game IS NOT Running???
-Ron
#5
02/08/2006 (6:42 am)
Hmmmm...darn, coulda sworn I tried that also. I'll give it a shot, thanks for your responses Matthew!
#6
function GameConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
commandToClient(%this, 'SetMaxLaps', $Game::Laps);
// Create a new camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Client controls the camera by default.
%this.setControlObject(%this.camera);
if(!$Game::Running)
{
// Create a car object.
%this.spawnCar();
// Orbit the camera around the car
%this.camera.setOrbitMode(%this.car, %this.car.getTransform(), 0.5, 4.5, 4.5);
}
}
I take Game::Running to mean on the client, not on the server? Otherwise, this wouldn't work.
Heck, I dunno...maybe this part of the code is obsoloete, and the car is getting spawned elsewhere...
02/08/2006 (6:45 am)
You know...that is a very good question, and I completely missed that. Here is the original function that was in starter.racing.function GameConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
commandToClient(%this, 'SetMaxLaps', $Game::Laps);
// Create a new camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Client controls the camera by default.
%this.setControlObject(%this.camera);
if(!$Game::Running)
{
// Create a car object.
%this.spawnCar();
// Orbit the camera around the car
%this.camera.setOrbitMode(%this.car, %this.car.getTransform(), 0.5, 4.5, 4.5);
}
}
I take Game::Running to mean on the client, not on the server? Otherwise, this wouldn't work.
Heck, I dunno...maybe this part of the code is obsoloete, and the car is getting spawned elsewhere...
Torque 3D Owner Matthew Langley
Torque
to
if that works modify your 5000 scheudle the same way