Game Development Community

Showing Vehicle Icon

by Matthias Schoeldgen · in Torque 3D Beginner · 01/23/2013 (1:55 am) · 3 replies

This seems to be a problem with tagged strings i can't track down. Let me show you what i've done. First the addition in the vehicles datablock:
category = "Vehicles";
   shapeFile = "art/shapes/Vehicles/Land/Willy/willy.dae";
   emap = 1;
   previewIcon = 'willy.png';
The new stuff is the previewIcon here. It resides in /art/gui/vehicleHUD/willy.png .
Then i added this in vehicle.cs:
function VehicleData::setMountVehicle(%this, %vehicle, %player)
{
   //echo("c4VehicleData::setMountVehicle("@ %this.getName() @", "@ %vehicle @", "@ %player.client.nameBase @")");

   if (isObject(%vehicle) && %vehicle.isEnabled())
   {
      %node = %this.findEmptySeat(%vehicle, %player);
      if (%node >= 0)
      {
         //echo("c4Mount Node: "@ %node);
         %vehicle.mountObject(%player, %node);
         //%player.playAudio(0, MountVehicleSound);
         %player.mVehicle = %vehicle;
        %preIcon = addTaggedString(%vehicle.getDataBlock().previewIcon);
		echo ("Image file is "@%preIcon);
        commandToClient(%player.client,"RefreshVehicleHealthHUD",%preIcon);
	%this.updateVehicleHealth(%vehicle);
      }
   }
}
function VehicleData::updateVehicleHealth(%data,%obj)
{
	%player = %obj.getMountNodeObject(0);
	if (isPlayer(%player))
	{		
  	 // Calculate vehicle health
  		%maxDamage = %data.maxDamage;
   		%damageLevel = %obj.getDamageLevel();
   		%curHealth = %maxDamage - %damageLevel;
   		%curHealth = mceil(%curHealth);

   // Send the object's current health level to the client, where it
   // will Update the numericalHealth HUD.
   		commandToClient(%player.client, 'SetVehicleHealthHUD', %curHealth);
   	}
}
This should add the filename as a tagged string, just like for a weapon preview and then send it all to the client.
Ok, now in client.cs i added that:
function clientCmdSetVehicleHealthHUD(%curHealth)
{
   // Skip if the hud is missing.
   if (!isObject(numericalVehicleHealthHUD))
      return;

   // The server has sent us our current health, display it on the HUD
   numericalVehicleHealthHUD.setValue(%curHealth);

   // Ensure the HUD is set to visible while we have health / are alive
   if (%curHealth)
      VehicleHealthHUD.setVisible(true);
   else
      VehicleHealthHUD.setVisible(false);
}
// set the icon for the Vehicle HUD
function clientCmdRefreshVehicleHealthHUD(%iconFile)
{
   if (%iconFile $= "") {
      VehicleImage.setVisible(false);//PreviewImage.setVisible(false);
      }
   else
   {
      VehicleImage.setVisible(true);//PreviewImage.setVisible(true);
      %theIcon ="art/gui/vehicleHud/"@ getTaggedString(%iconFile);   // this line is causing error
	  echo("Icon is "@%theIcon);
      VehicleImage.setbitmap(%theIcon);
   }
}
// this switches key map and HUD visibilty
function clientCmdtoggleVehicleMap(%toggle)
{
   if(%toggle)
   {
    moveMap.pop();
    vehicleMap.push();
    setvehicleHUD(true);
   }
   else
   {
    vehicleMap.pop();
    moveMap.push();
    setvehicleHUD(false);
   }
}
function setvehicleHUD(%visibility)
{
	VehicleHealthHUD.setVisible(%visibility);
}
The result is that i can display the vehicle health value very well but for the icon i always get an error:
'Remote Command Error - command must be a tag.'
But when using the console to find out about the taggedString i get back the correct result, like 'willy.png'. So what am i doing wrong? Oh, on a sidenote the Vehicle HUD GUI is built just like the standard weapon HUD using hudfill, bitmap and the numerical value.

About the author

Coder, Modeller and Texturer for the eXperience World War 2 (XWW2) Modification for BF2 and BF1942. Playing Bass Guitar and doing electronics in real life.


#1
01/23/2013 (6:14 am)
The thing is, a tag is enclosed in single quotes ( ' ' ) not double quotes ( " " ). So this:
%theIcon ="art/gui/vehicleHud/"@ getTaggedString(%iconFile);
should be this:
%theIcon ='art/gui/vehicleHud/'@ getTaggedString(%iconFile);
You might have to tag the whole value.
#2
01/23/2013 (7:56 am)
Uhm, but this is all client side already and it mimics the weapon HUD lines which are e.g:
PreviewImage.setbitmap("art/gui/weaponHud/"@ detag(%preview));

I tried your suggestion, but still no cigar and the error remains the same: Remote Command Error - command must be a tag.

But nevertheless i found one error. As my icon string is already single quoted its already a tag and this line
%preIcon = addTaggedString(%vehicle.getDataBlock().previewIcon);

becomes this:
%preIcon = %vehicle.getDataBlock().previewIcon;

I now can 'echo (getTaggedString(%preIcon));' in the console and get 'willy.png' (without the quotes) as the answer. So far so good. But the remote command error remains unfortunately.
Edit: Aaargh , you know what?It was a typo - this here is the faulty line:
commandToClient(%player.client,"RefreshVehicleHealthHUD",%preIcon);
which should have been:
commandToClient(%player.client,'RefreshVehicleHealthHUD',%preIcon);
So of course you were right, it was the wrong quotes, although on a different line. The command name was not a tag, gee... Thanks for your help, Richard - it really does help to have someone to discuss that.


#3
01/23/2013 (9:27 am)
Those typos can drive a person crazy...

I did the same thing with a trigger using the commandToClient function.
Rewrote the trigger three times before I realized that I was using quotes.

I digress...