Game Development Community

Error in PlayGui

by Greyfort · in Torque 3D Professional · 11/20/2011 (7:47 pm) · 10 replies

scripts/gui/playGui.cs Line: 6 - syntax error
>>> Advanced script error report. Line 6.
>>> Some error context, with ## on sides of error halt:

this is the error I get.
this is line 6 #include "chkobj_v1.h"

this is my include script

//-------------------------------------
// File: chkobj_v1.h
// Author: Greyfort
// Discription:
/*
finds object types, handles objects
*/
//

// Stuff game types into the console with an array if possible
$type[0]=$TypeMasks::StaticObjectType;
$type[1]=$TypeMasks::EnvironmentObjectType;
$type[2]=$TypeMasks::TerrainObjectType;
$type[3]=$TypeMasks::InteriorObjectType;
$type[4]=$TypeMasks::WaterObjectType;
$type[5]=$TypeMasks::TriggerObjectType;
$type[6]=$TypeMasks::MarkerObjectType;
$type[7]=$TypeMasks::GameBaseObjectType;
$type[8]=$TypeMasks::ShapeBaseObjectType;
$type[9]=$TypeMasks::CameraObjectType;
$type[10]=$TypeMasks::StaticShapeObjectType;
$type[11]=$TypeMasks::DynamicShapeObjectType;
$type[12]=$TypeMasks::PlayerObjectType;
$type[13]=$TypeMasks::ItemObjectType;
$type[14]=$TypeMasks::VehicleObjectType;
$type[15]=$TypeMasks::VehicleBlockerObjectType;
$type[16]=$TypeMasks::ProjectileObjectType;
$type[17]=$TypeMasks::ExplosionObjectType;
$type[18]=$TypeMasks::CorpseObjectType;
$type[19]=$TypeMasks::DebrisObjectType;
$type[20]=$TypeMasks::PhysicalZoneObjectType;
$type[21]=$TypeMasks::LightObjectType;

// GetObjectType function
void int GetObjectType(%thistype=0)
{
%count=0;
while(%count <21)
{
if (%thistype == $type[%count] ){%thistype == $type[%count];}
%count++;
}
echo("Object_Type="+%thistype+"");
return %thistype;
// end of GetObjectType
}

// GetIsObjectValid function
void int GetIsObjectValid(%thistype=false)
{
%count=0;
while(%count <21)
{
if (%thistype == $type[%count] ){%thistype==true;}
%count++;
}
echo("Object_Type="+%thistype+"");
return %thistype;
// end of GetIsObjectValid
}

I'm not sure what I did wrong or why there is syntax, im not finding any answers in Torgue 3D script manual. If any body sees any thing that be great. I'll keep trying

About the author

Computer programming/repair,3D Modeling,anim,Game Dev.


#1
11/20/2011 (8:17 pm)
The problem is you have a mixture of TorqueScipt and C. TorqueScript doesn't use headers and you can't include other scripts. It seems you may have confused the .cs files for C# when they're actually TorqueScript. The .cs actually stands for C Script and was chosen as the extension for the script files by Dynamix back in the Tribes days (pre-GG and Torque). C# wasn't around back then so there was no possible conflict with the extension.

In order for your script to be usable it first needs to saved as a .cs. Next remove the return types, TorqueScript doesn't make use of them, and preface your functions with "function ".

Example:
function foo(%arg1, %arg2)
{
   if(%arg1 < %arg2)
      echo("Foo");
   else
      echo("Bar");
}

Scripts are loaded using the exec() command, you could consider it a psuedo include but it's best not to think of it that way (I did when first started out years ago and it resulted in some sloppy code). The exec() command simply loads the script and once a script has been loaded the functions in it are available for use in any other script as well.

I highly recommend checking out the new FPS Tutorial, especially the section on scripting. That will help you get a better understanding of how TorqueScript works and is a bit more in-depth than my quick explanation.
#2
11/20/2011 (9:07 pm)
// function - Is a keyword telling TorqueScript we are defining a new function.
// function_name - Is the name of the function we are creating.
// ... - Is any number of additional arguments.
// statements - Your custom logic executed when function is called
// return val - The value the function will give back after it has completed. Optional.

function function_name([arg0],...,[argn])
{
statements;
[return val;]
}
from torque script manual

ok so I added code to top of playgui...

// Stuff game types into the console with an array if possible
$type[0]=$TypeMasks::StaticObjectType;
$type[1]=$TypeMasks::EnvironmentObjectType;
$type[2]=$TypeMasks::TerrainObjectType;
$type[3]=$TypeMasks::InteriorObjectType;
$type[4]=$TypeMasks::WaterObjectType;
$type[5]=$TypeMasks::TriggerObjectType;
$type[6]=$TypeMasks::MarkerObjectType;
$type[7]=$TypeMasks::GameBaseObjectType;
$type[8]=$TypeMasks::ShapeBaseObjectType;
$type[9]=$TypeMasks::CameraObjectType;
$type[10]=$TypeMasks::StaticShapeObjectType;
$type[11]=$TypeMasks::DynamicShapeObjectType;
$type[12]=$TypeMasks::PlayerObjectType;
$type[13]=$TypeMasks::ItemObjectType;
$type[14]=$TypeMasks::VehicleObjectType;
$type[15]=$TypeMasks::VehicleBlockerObjectType;
$type[16]=$TypeMasks::ProjectileObjectType;
$type[17]=$TypeMasks::ExplosionObjectType;
$type[18]=$TypeMasks::CorpseObjectType;
$type[19]=$TypeMasks::DebrisObjectType;
$type[20]=$TypeMasks::PhysicalZoneObjectType;
$type[21]=$TypeMasks::LightObjectType;

// GetObjectType function
// GetIsObjectValid function
function GetIsObjectValid(%thistype)
{
%count=0;
while(%count <=21)
{
if (%thistype == $type[%count] ){%thistype=true;}
%count++;
}
echo("Object_Type=",%thistype);
[return %thistype;]
// end of GetIsObjectValid
}

// GetObjectType function
function GetObjectType(%thistype=0.1)
{
%count=0;
while(%count <=21)
{
if (%thistype == $type[%count] ){%thistype = $type[%count];}
%count++;
}
echo("Object_Type=",%thistype);
[return %thistype;]
// end of GetObjectType
}

and now I get error:
scripts/gui/playGui.cs Line: 37 - syntax error
>>> Advanced script error report. Line 37.
>>> Some error context, with ## on sides of error halt:

line 37 = function GetObjectType(%thistype=0.1)

what I want it to do is 1 function check if its a valid type, next check type
#3
11/20/2011 (9:24 pm)
There are more than problems with syntax in your script. You are comparing an integer value and then setting it to a boolean value. Granted, this will compile but it won't do what you are wanting it to.

if (%thistype == $type[%count] ){%thistype=true;}

What are you attempting to do here?

#4
11/20/2011 (9:54 pm)
oh I didn't catch that I'm trying to Id the mask types from the array.

#5
11/21/2011 (3:18 am)
so other then....
if( %thistype == $TypeMasks::StaticObjectType )

is there no way to get the $TypeMasks::StaticObjectType into a function?
#6
11/23/2011 (1:17 pm)
Few years back I've done one helper function for debugging complex stuff I was prototyping:
function testForObjectType(%mask)
{
   if (%mask & $TypeMasks::CameraObjectType) echo("CameraObjectType");
   if (%mask & $TypeMasks::CorpseObjectType) echo("CorpseObjectType");
   if (%mask & $TypeMasks::DamagableItemObjectType) echo("DamagableItemObjectType");
   if (%mask & $TypeMasks::DebrisObjectType) echo("DebrisObjectType");
   if (%mask & $TypeMasks::EnvironmentObjectType) echo("EnvironmentObjectType");
   if (%mask & $TypeMasks::ExplosionObjectType) echo("ExplosionObjectType");
   if (%mask & $TypeMasks::ForceFieldObjectType) echo("ForceFieldObjectType");
   if (%mask & $TypeMasks::GameBaseObjectType) echo("GameBaseObjectType");
   if (%mask & $TypeMasks::InteriorMapObjectType) echo("InteriorMapObjectType");
   if (%mask & $TypeMasks::InteriorObjectType) echo("InteriorObjectType");
   if (%mask & $TypeMasks::ItemObjectType) echo("ItemObjectType");
   if (%mask & $TypeMasks::MarkerObjectType) echo("MarkerObjectType");
   if (%mask & $TypeMasks::PhysicalZoneObjectType) echo("PhysicalZoneObjectType");
   if (%mask & $TypeMasks::PlayerObjectType) echo("PlayerObjectType");
   if (%mask & $TypeMasks::ProjectileObjectType) echo("ProjectileObjectType");
   if (%mask & $TypeMasks::ShapeBaseObjectType) echo("ShapeBaseObjectType");
   if (%mask & $TypeMasks::StaticObjectType) echo("StaticObjectType");
   if (%mask & $TypeMasks::StaticRenderedObjectType) echo("StaticRenderedObjectType");
   if (%mask & $TypeMasks::StaticShapeObjectType) echo("StaticShapeObjectType");
   if (%mask & $TypeMasks::StaticTSObjectType) echo("StaticTSObjectType");
   if (%mask & $TypeMasks::TerrainObjectType) echo("TerrainObjectType");
   if (%mask & $TypeMasks::TriggerObjectType) echo("TriggerObjectType");
   if (%mask & $TypeMasks::VehicleBlockerObjectType) echo("VehicleBlockerObjectType");
   if (%mask & $TypeMasks::VehicleObjectType) echo("VehicleObjectType");
   if (%mask & $TypeMasks::WaterObjectType) echo("WaterObjectType");
}
#7
11/23/2011 (1:17 pm)
Can't fit it in one post.. so, continuing:

Another:
function testForObjectTypeObject(%obj)
{
   if (!isObject(%obj))
   {
      error("Specified object (" @ %obj @ ") is not real one.");
      return;
   }
   if (%obj.getType() & $TypeMasks::CameraObjectType) echo("CameraObjectType");
   if (%obj.getType() & $TypeMasks::CorpseObjectType) echo("CorpseObjectType");
   if (%obj.getType() & $TypeMasks::DamagableItemObjectType) echo("DamagableItemObjectType");
   if (%obj.getType() & $TypeMasks::DebrisObjectType) echo("DebrisObjectType");
   if (%obj.getType() & $TypeMasks::EnvironmentObjectType) echo("EnvironmentObjectType");
   if (%obj.getType() & $TypeMasks::ExplosionObjectType) echo("ExplosionObjectType");
   if (%obj.getType() & $TypeMasks::ForceFieldObjectType) echo("ForceFieldObjectType");
   if (%obj.getType() & $TypeMasks::GameBaseObjectType) echo("GameBaseObjectType");
   if (%obj.getType() & $TypeMasks::InteriorMapObjectType) echo("InteriorMapObjectType");
   if (%obj.getType() & $TypeMasks::InteriorObjectType) echo("InteriorObjectType");
   if (%obj.getType() & $TypeMasks::ItemObjectType) echo("ItemObjectType");
   if (%obj.getType() & $TypeMasks::MarkerObjectType) echo("MarkerObjectType");
   if (%obj.getType() & $TypeMasks::PhysicalZoneObjectType) echo("PhysicalZoneObjectType");
   if (%obj.getType() & $TypeMasks::PlayerObjectType) echo("PlayerObjectType");
   if (%obj.getType() & $TypeMasks::ProjectileObjectType) echo("ProjectileObjectType");
   if (%obj.getType() & $TypeMasks::ShapeBaseObjectType) echo("ShapeBaseObjectType");
   if (%obj.getType() & $TypeMasks::StaticObjectType) echo("StaticObjectType");
   if (%obj.getType() & $TypeMasks::StaticRenderedObjectType) echo("StaticRenderedObjectType");
   if (%obj.getType() & $TypeMasks::StaticShapeObjectType) echo("StaticShapeObjectType");
   if (%obj.getType() & $TypeMasks::StaticTSObjectType) echo("StaticTSObjectType");
   if (%obj.getType() & $TypeMasks::TerrainObjectType) echo("TerrainObjectType");
   if (%obj.getType() & $TypeMasks::TriggerObjectType) echo("TriggerObjectType");
   if (%obj.getType() & $TypeMasks::VehicleBlockerObjectType) echo("VehicleBlockerObjectType");
   if (%obj.getType() & $TypeMasks::VehicleObjectType) echo("VehicleObjectType");
   if (%obj.getType() & $TypeMasks::WaterObjectType) echo("WaterObjectType");
}
#8
11/23/2011 (1:17 pm)
And one more:
function testForObjectTypeObjectLine(%obj)
{
   if (!isObject(%obj))
   {
      error("Specified object (" @ %obj @ ") is not real one.");
      return;
   }
   %type = "";
   if (%obj.getType() & $TypeMasks::StaticObjectType) %type = %type SPC "StaticObjectType";
   
   if (%obj.getType() & $TypeMasks::EnvironmentObjectType) %type = %type SPC "EnvironmentObjectType";
   if (%obj.getType() & $TypeMasks::TerrainObjectType) %type = %type SPC "TerrainObjectType";
   if (%obj.getType() & $TypeMasks::InteriorObjectType) %type = %type SPC "InteriorObjectType";
   if (%obj.getType() & $TypeMasks::WaterObjectType) %type = %type SPC "WaterObjectType";
   if (%obj.getType() & $TypeMasks::TriggerObjectType) %type = %type SPC "TriggerObjectType";
   if (%obj.getType() & $TypeMasks::MarkerObjectType) %type = %type SPC "MarkerObjectType";
   if (%obj.getType() & $TypeMasks::AtlasObjectType) %type = %type SPC "AtlasObjectType";
   if (%obj.getType() & $TypeMasks::InteriorMapObjectType) %type = %type SPC "InteriorMapObjectType";
   if (%obj.getType() & $TypeMasks::DecalManagerObjectType) %type = %type SPC "DecalManagerObjectType";

   if (%obj.getType() & $TypeMasks::GameBaseObjectType) %type = %type SPC "GameBaseObjectType";
   if (%obj.getType() & $TypeMasks::ShapeBaseObjectType) %type = %type SPC "ShapeBaseObjectType";
   if (%obj.getType() & $TypeMasks::CameraObjectType) %type = %type SPC "CameraObjectType";
   if (%obj.getType() & $TypeMasks::StaticShapeObjectType) %type = %type SPC "StaticShapeObjectType";
   if (%obj.getType() & $TypeMasks::PlayerObjectType) %type = %type SPC "PlayerObjectType";
   if (%obj.getType() & $TypeMasks::ItemObjectType) %type = %type SPC "ItemObjectType";
   if (%obj.getType() & $TypeMasks::VehicleObjectType) %type = %type SPC "VehicleObjectType";
   if (%obj.getType() & $TypeMasks::VehicleBlockerObjectType) %type = %type SPC "VehicleBlockerObjectType";
   if (%obj.getType() & $TypeMasks::ProjectileObjectType) %type = %type SPC "ProjectileObjectType";
   if (%obj.getType() & $TypeMasks::ExplosionObjectType) %type = %type SPC "ExplosionObjectType";
   if (%obj.getType() & $TypeMasks::CorpseObjectType) %type = %type SPC "CorpseObjectType";
   if (%obj.getType() & $TypeMasks::ForceFieldObjectType) %type = %type SPC "ForceFieldObjectType";
   if (%obj.getType() & $TypeMasks::DebrisObjectType) %type = %type SPC "DebrisObjectType";
   if (%obj.getType() & $TypeMasks::PhysicalZoneObjectType) %type = %type SPC "PhysicalZoneObjectType";
   if (%obj.getType() & $TypeMasks::StaticTSObjectType) %type = %type SPC "StaticTSObjectType";
   if (%obj.getType() & $TypeMasks::AIObjectType) %type = %type SPC "AIObjectType";
   if (%obj.getType() & $TypeMasks::StaticRenderedObjectType) %type = %type SPC "StaticRenderedObjectType";

   if (%obj.getType() & $TypeMasks::DamagableItemObjectType) %type = %type SPC "DamagableItemObjectType";

   if (%obj.getType() & $TypeMasks::ShadowCasterObjectType) %type = %type SPC "ShadowCasterObjectType";
   if (%obj.getType() & $TypeMasks::TurretObjectType) %type = %type SPC "TurretObjectType";


   return trim(%type);
}

Notice: this is from a modified engine, so those functions can cover not all possible objects types defined by engine, or may include some that are not in engine at all. So, be careful when taking this.
#9
11/23/2011 (1:20 pm)
Here is an example of how to setup such "helpers":
function isValidStaticObject(%obj)
{
   if(!isObject(%obj))
   {
      error("isValidStaticObject() error: object" SPC %obj SPC "not found or you have passed not an object at all!");
      return false;
   }
   if(!%obj.isMethod("getType"))
   {
      error("isValidStaticObject() error: object" SPC %obj SPC "doesn't have getType() method, so it's not valid!");
      return false;
   }
   return ( (%obj.getType() & $TypeMasks::StaticObjectType) != 0 );
}
#10
11/25/2011 (12:25 pm)
Thanks Fyodor, I kind of wondered about if statements instead of array and loops.