I'm trying to make a function that returns an object which is directly or within a few Torque Units of your camera. I've copied part of the code below from Return to Blockland, and it seems to be a generic Torque function. I edited it slightly as I don't have access to a client's GUI functions and whether a client clicked something or not, so I'm using getEyeVector/Point:
function serverCmdSelectObject(%client)
{
// mouseVec = vector from camera point to 3d mouse coords (normalized)
%mouseVec = %client.player.getEyeVector();
// cameraPoint = the world position of the camera
%cameraPoint = %client.player.getEyePoint();
messageclient(%client,"","%cameraPoint = " @ %cameraPoint);
messageclient(%client,"","Transform = " @ %client.player.getTransform());
//Determine how far should the picking ray extend into the world?
%selectRange = 2;
// scale mouseVec to the range the player is able to select with mouse
%mouseScaled = VectorScale(%mouseVec, %selectRange);
// cameraPoint = the world position of the camera
// rangeEnd = camera point + length of selectable range
%rangeEnd = VectorAdd(%cameraPoint, %mouseScaled);
// Search for anything that is selectable – below are some examples
%searchMasks = $TypeMasks::PlayerObjectType | $TypeMasks::CorpseObjectType |
$TypeMasks::ItemObjectType | $TypeMasks::TriggerObjectType;
// Search for objects within the range that fit the masks above
// If we are in first person mode, we make sure player is not selectable by setting fourth parameter (exempt
// from collisions) when calling ContainerRayCast
%player = %client.player;
if ($firstPerson)
{
%scanTarg = ContainerRayCast (%cameraPoint, %rangeEnd, %searchMasks, %player);
}
else //3rd person - player is selectable in this case
{
%scanTarg = ContainerRayCast (%cameraPoint, %rangeEnd, %searchMasks);
}
// a target in range was found so select it
messageclient(%client,"","%scanTarg = " @ %scanTarg);
if (%scanTarg)
{
%targetObject = firstWord(%scanTarg);
messageclient(%client,"",%targetObject);
}
messageclient(%client,"","Done");
}
The code seems to return when I am looking at a clone of myself (the only bot availiable right now made with %client.createPlayer();) but not when I look at an interior, brick, item or any vehicle other than a Horse - a player 'Armour' object. How, in particular, would I get it to return on the Item or Brick?
EDIT: Also, does Torque have arrays, and if yes, what syntax do you use to make them work?