Game Development Community

Scripting in a light object

by Edith Cowan University (#0002) · in Torque Game Engine · 09/01/2008 (6:53 am) · 1 replies

Hi all

I am new to torque and have searched high and low for a solution to what I am trying to do and have not found a solution. I want to be able to add a light object the same way you would add a static object but from a script. Rather then place the object using the world editor that is I want to be able to add them using a script if possible. I know how to add a static object with script and have been successful, what I am after is a way to add a light based on say the sgSpotDataBlock found in the common->lighting->lights directory.

To create a static shape instance you would use something like

%obj = new StaticShape(){};

I don't have the TLK so what would be the equivalent for a light. I am not worried if you have to specify the type of light.

This is the declaration for the sgSpotDataBlock

sgUniversalStaticLightData(sgSpotDataBlock)

I thought to construct an object of this type based on the naming conventions would be somehting like

%obj = new sgUniversalStaticLight(){};

Tried this and got the error it is not part of the GameBase class

A pointer to a class reference that I might find useful.

Thanks in advance

#1
09/01/2008 (1:00 pm)
Which version of torque are you using? You only need tlk if you are using a pre 1.5 version of the engine.
To get your light working, place it's datablock at the top of your static shape script. I'll use your example to show you.

//--- OBJECT WRITE BEGIN ---
datablock sgUniversalStaticLightData(sgDefaultLightDataBlock) {
   className = "sgUniversalStaticLightData";
   LightOn = "1";
   Radius = "10";
   Brightness = "1";
   Colour = "1.000000 1.000000 1.000000 1.000000";
   FlareOn = "0";
   FlareTP = "1";
   FlareColour = "1.000000 1.000000 1.000000 1.000000";
   ConstantSizeOn = "0";
   ConstantSize = "1";
   NearSize = "3";
   FarSize = "0.5";
   NearDistance = "10";
   FarDistance = "30";
   FadeTime = "0.1";
   BlendMode = "0";
   AnimColour = "0";
   AnimBrightness = "0";
   AnimRadius = "0";
   AnimOffsets = "0";
   AnimRotation = "0";
   LinkFlare = "1";
   LinkFlareSize = "0";
   MinColour = "0.000000 0.000000 0.000000 1.000000";
   MaxColour = "1.000000 1.000000 1.000000 1.000000";
   MinBrightness = "0";
   MaxBrightness = "1";
   MinRadius = "0.1";
   MaxRadius = "20";
   StartOffset = "-5 0 0";
   EndOffset = "5 0 0";
   MinRotation = "0";
   MaxRotation = "359";
   SingleColourKeys = "1";
   RedKeys = "AZA";
   GreenKeys = "AZA";
   BlueKeys = "AZA";
   BrightnessKeys = "AZA";
   RadiusKeys = "AZA";
   OffsetKeys = "AZA";
   RotationKeys = "AZA";
   ColourTime = "5";
   BrightnessTime = "5";
   RadiusTime = "5";
   OffsetTime = "5";
   RotationTime = "5";
   LerpColour = "1";
   LerpBrightness = "1";
   LerpRadius = "1";
   LerpOffset = "1";
   LerpRotation = "1";
   StaticLight = "0";
   SpotLight = "0";
   SpotAngle = "1";
   AdvancedLightingModel = "1";
   EffectsDTSObjects = "1";
};

%obj = new StaticShape(){
// Shapes data here
// %obj.attach(sgDefaultLightDataBlock);
};
Torque isn't OOP enabled, so what the game is telling you is that it can't find your light datablock. Here, it will have no problems finding it.
Hope this gets you going.