Game Development Community

How should I find the %client of a camera ?

by Vis · in Torque Game Engine · 11/20/2008 (7:42 am) · 3 replies

I am using the pathedCamera resource.
In GameConnection::onClientEnterGame() I set up a pathed camera thus;

%this.PathCamera = new PathCamera() {
		dataBlock = LoopingCam;
		position = "0 0 300 1 0 0 0";
	};

	%this.PathCamera.followPath("MissionGroup/Paths/PathOne");
	MissionCleanup.add( %this.PathCamera);
	%this.PathCamera.scopeToClient(%this);

	$Server::Client = %this;
	%this.setControlObject(%this.PathCamera);

I have created a script callback onTarget() that gets called when the camera arrives at the end of the path and I want to send a command to the client that owns the camera, I found this works :-


function LoopingCam::onTarget(%this,%camera){

	for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
		
		%cl = ClientGroup.getObject( %clientIndex );
		if(%cl.getCameraObject() == %camera)
		{
			commandToClient(%cl,'DisplayLogin');
			break;
		}
	}
}

Is this the correct approach ?

or is there a method something like:

%cl = %camera.getThisCamerasClientID()

#1
11/20/2008 (8:36 am)
That probably works, but way too complicated.. just issue a client variable to the camera when you create it:

%this.PathCamera = new PathCamera() {
		dataBlock = LoopingCam;
		position = "0 0 300 1 0 0 0";
	};
	%this.PathCamera.client = %this;

... and get it right from the camera when you need it:

function LoopingCam::onTarget(%this,%camera) {
	%client = %camera.client;
}
#2
11/20/2008 (12:06 pm)
Thanks Konrad
#3
11/21/2008 (10:19 am)
A simple decision is using the global scope on server side.
Then use it in client side scripts.