Game Development Community

Simple question about programming terms

by Nicolai Dutka · in Torque Game Engine Advanced · 05/22/2009 (3:55 pm) · 6 replies

I am trying to make a function and cannot get it to do anything at all...

datablock staticShapeData( Switch_LiftRiser1 )
{
   category = "StaticShape";

   shapeFile = "~/data/shapes/ALPHA/Cube_1m.dts";
   emap = true;
};

function Switch_LiftRiser1::onActivate(%this)
{
   liftRiser(%this.target);
}

function makeSwitch_LiftRiser(%mesh,%tex,%target)
{
   //%mesh = which mesh to use - determined by datablock
   //%tex = which texture to use - each mesh will have multiple textures
   //%target = the NAME of the riser you want this switch to LIFT
   %newSwitch = new staticShape() {
      canSaveDynamicFields = "1";
      Enabled = "1";
      dataBlock = "Switch_LiftRiser"@ %mesh;
      static = "1";
      scale = "1 1 1";
   };
   %newSwitch.setTransform($player.getTransform());
   switches.add(%newSwitch);
   %newSwitch.setName("Switch_LiftRiser_"@ switches.getCount());
   %newSwitch.target = %target;
   return %newSwitch;
}


In the code above, "Switch_LiftRiser1::onActivate" what are the proper terms for the item BEFORE the "::" and for the item AFTER the "::" and, what is the term for the "::"?


I need to know those terms so I can talk about this stuff intelligently...

Anyway, I can run the "make" function to create my object in game, but when I turn around and tell it: %obj.onActivate(), NOTHING AT ALL HAPPENS!!! I don't understand this at all...

#1
05/22/2009 (4:40 pm)
%newSwitch.setTransform($player.getTransform());
if I am correct should be (%client.getTransform());
#2
05/22/2009 (4:48 pm)
no, i have $player declared in game.cs:


$player = %client;


So that I can call on $player any time I want. ;)


What you see above is the ENTIRE file: switchObject.cs
#3
05/22/2009 (9:48 pm)
Quote:
I can run the "make" function to create my object in game, but when I turn around and tell it: %obj.onActivate(), NOTHING AT ALL HAPPENS!!! I don't understand this at all...
How are you obtaining the object ID that you are referencing with that %obj? Which by the way is only local to the function to which it is contained in. Simply calling %obj.onActivate() doesn't magically make it work, something has to pass that information into it in order to know what %obj is -- and I don't see that in the code above. Your usage of what you have shown is actually kind of confusing to me.

Is "onActivate" supposed to be a callback (which happens automatically), or is it simply a function name? You might want to try using the "onAdd" callback in order to start the activate sequence.

And to help you in understanding your question about "Namespace" (and other terminology) peruse these pages in the TDN documentaion:
TorqueScript
TorqueScript Quick Reference
#4
05/22/2009 (9:58 pm)
"%obj.onActivate" is just an example... In-game, I open the mission editor and just look at the object ID number and use that:

2262.onActivate();

onActivate is supposed to be a callback that happens automatically and it CANNOT be in "onAdd". The object is supposed to be in the level and waiting for something to happen (like pulling a lever) before it is activated.

So... I can't create my own callback methods?
#5
05/22/2009 (10:01 pm)
I actually ended up re-writing the code and coming up with something much nicer:

datablock staticShapeData( SwitchObject1 )
{
   category = "StaticShape";

   shapeFile = "~/data/shapes/ALPHA/Cube_1m.dts";       // Give this a unique mesh
   emap = true;
};

datablock staticShapeData( SwitchObject2 )
{
   category = "StaticShape";

   shapeFile = "~/data/shapes/ALPHA/Cube_1m.dts";       // Give this a unique mesh
   emap = true;
};

function makeSwitchObject(%mesh,%tex,%action,%target)
{
   //%mesh = which mesh to use - determined by datablock
   //%tex = which texture to use - each mesh will have multiple textures
   //%target = the NAME of the riser you want this switch to LIFT
   %newSwitch = new staticShape() {
      canSaveDynamicFields = "1";
      Enabled = "1";
      dataBlock = "SwitchObject"@ %mesh;
      static = "1";
      scale = "1 1 1";
   };
   %newSwitch.setTransform($player.getTransform());
   switches.add(%newSwitch);
   %newSwitch.setName("SwitchObject_"@ switches.getCount());
   %newSwitch.lever = 1;
   %newSwitch.action = %action;
   %newSwitch.target = %target;
   return %newSwitch;
}

I like it. :)
#6
05/22/2009 (10:04 pm)
I then have this:

%distance = 1.65; // Distance in front of eyePoint
  %start = $player.getEyePoint();
  %vector = $player.getEyeVector();
  %vectorN = VectorNormalize(%vector);
  %vectorS = VectorScale(%vectorN,%distance);
  %end = VectorAdd(%vectorS,%start);
  
  %ray = ContainerRayCast(%start,%end,$TypeMasks::StaticShapeObjectType);

  if(%ray)
  {

if(%ray.Lever)
     {
       $Lever = %ray;
       //disable controls
       toggleControls();
       call(%ray.action, %ray.target);  // Calls the function defined by %ray.action and runs it on %ray.target
       //play animations
       //run a little code for the lever
       //enable controls
       schedule(1000,0,toggleControls);
     }
}

It's a work in progress, but this let's me use "E" to have the player activate levers. For the record, this is just a piece of my code... our ray actually checks for a lot of other object types and does various actions for each ;)