Game Development Community

Lost

by Anthony Ratcliffe · in Torque Game Engine · 12/28/2008 (1:47 am) · 16 replies

I have to scripts and i cant work out why there not working the first is a blinking light one constantly going on and off. the second is a trigger that asks if the mount point is equal to true if not apply damage. NO ERRORS but it simply wont work

datablock fxLightData(lightDB22red) {
LightOn = true;
Radius = 0.25;
Brightness = 1.0;
Colour = "1 0 0";
FlareOn = true;
FlareTP = true;
FlareBitmap = "common/lighting/corona";
FlareColour = "1 0 0";
ConstantSizeOn = false;
ConstantSize = 1.0;
NearSize = 3.0;
FarSize = 0.5;
NearDistance = 10.0;
FarDistance = 30.0;
FadeTime = 0.1;
BlendMode = 0;
AnimColour = false;
AnimBrightness = false;
AnimRadius = false;
AnimOffset = true;
AnimRotation = false;
LinkFlare = true;
LinkFlareSize = false;
MinColour = "0 0 0";
MaxColour = "1 0 0";
MinBrightness = 0.0;
MaxBrightness = 1.0;
MinRadius = 0.1;
MaxRadius = 20.0;
StartOffset = "-5 0 0";
EndOffset = "5 0 0";
MinRotation = 0;
MaxRotation = 350;
SingleColourKeys = true;
RedKeys = "AZA";
GreenKeys = "AZA";
BlueKeys = "AZA";
BrightnessKeys = "AZA";
RadiusKeys = "AZA";
OffsetKeys = "AZA";
RotationKeys = "AZA";
ColourTime = 1.0;
BrightnessTime = 1.0;
RadiusTime = 5.0;
OffsetTime = 5.0;
RotationTime = 5.0;
LerpColour = true;
LerpBrightness = true;
LerpRadius = true;
LerpOffset = true;
LerpRotation = true;
};


function OnOff(%time, %simgroup, %command)
{

if (%this.lightOn == false)
{
OnOff.schedule(5000,"lightOn");
%this.lightOn = true;
}
else
{
OnOff.schedule(5000,"lightOn");
%this.lightOn = false;
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SECOND SCRIPT TRIGGER MOUNT
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


datablock TriggerData(DefaultTrigger)
{
tickPeriodMS = 1000;
};


//-----------------------------------------------------------------------------

function DefaultTrigger::onEnterTrigger(%this,%trigger,%obj)
{
if (%obj.getClassName() $= "Player" )
{
if(%player.getMountedImage(3) == 0 )
{
%obj.applyDamage(2);
}

}
Parent::onEnterTrigger(%this,%trigger,%obj);
}

function DefaultTrigger::onLeaveTrigger(%this,%trigger,%obj)
{

Parent::onLeaveTrigger(%this,%trigger,%obj);
}

function DefaultTrigger::onTickTrigger(%this,%trigger)
{
// %this.getNumObjects();
// %this.getObject(n);
Parent::onTickTrigger(%this,%trigger);
}

#1
12/28/2008 (8:02 pm)
One thing that comes to mind to check on is your use of schedule, in this case the OnOff.schedule() usage. Is OnOff an object or just a function? If it's just the name of the function, then you should go with the general schedule() usage because I don't think it would work by using a function name as the calling object. I can be wrong on that (and if anyone knows otherwise, I think both me and Anthony could benefit from the answer), but it is worth investigating.
#2
12/29/2008 (7:32 am)
Changed the function OnOff(%time, %simgroup, %command)
to function lightOn (%time, %simgroup, %command)


Errors appeared not sure if there related



Tried to get the object for item 678, which is not InspectorData!
(0): Unknown command uninspect.
Object Inspector(2676) Inspector -> GuiInspector -> GuiStackControl -> GuiControl -> SimGroup -> SimSet -> SimObject
Tried to get the object for item 678, which is not InspectorData!
Tried to get the object for item 678, which is not InspectorData!
#3
12/29/2008 (7:58 am)
Seems that there's a bit of functionality going on that is not posted. Changing the function name does nothing if you're still calling that schedule as %obj.schedule() and that %obj is not referenced anywhere but when calling the schedule. On the other hand, if lightOn/lightOff are not functions, then the schedule also does not work because it's not calling anything that exists.

function OnOff(%time, %simgroup, %command)
{
   if (%this.lightOn == false)
   {
      OnOff.schedule(5000,"lightOn");
      %this.lightOn = true;
   }
   else
   {
      OnOff.schedule(5000,"lightOn");
      %this.lightOn = false;
   }
}

I changed the above to:

function OnOff(%obj) //<- you weren't using the other arguments inside the function, so I took them out
{
   if (%obj.lightOn == false)
   {
      schedule(5000,"lightOn", %obj);
   }
   else
   {
      schedule(5000,"lightOff", %obj);
   }
}

function lightOn(%obj)
{
   %obj.lightOn = true;
}

function lightOff(%obj)
{
   %obj.lightOn = false;
}

Like I said, there's a bit of functionality that was not posted, so I won't even try to speculate on the InspectorData stuff. I rewrote the functions like I would have done them in the context of the one function that was posted- it looks like changes were made in other areas when that function was renamed to cause the other errors, but I don't know. Hope it helps.
#4
12/29/2008 (10:46 am)
Tried the code posting no errors but still no flashing/blinking so i tried this with the help of tim still nothing


function lightDB22red::OnAdd(%this,%obj)
{
   echo("are u working");
   %obj.schedule(5000, toggleLight);
}


function fxLight::toggleLight(%this)
{
  if(%this.LightOn = false)
 {
     %this.LightOn = true;
     echo("The light is on");
 }
  else 
 {
      %this.LightOn = false;
      echo("The light is off");
      
  }
}

%this.schedule(5000, toggleLight);
#5
12/29/2008 (11:34 am)
Quote:if(%this.LightOn = false)

Needs to be:

Quote:if(%this.LightOn == false)

The former is an assignment, so your if statement always sets %this.LightOn to false, whereas the latter tests to see if %this.LightOn is false. But still, looking at your code, I'm left with questions.

function lightDB22red::OnAdd(%this,%obj)
{
   echo("are u working");
   %obj.schedule(5000, toggleLight);
}

In the above, you list the function OnAdd, a member of the lightDB22red namespace. However, while there is a %this argument that you should probably be using for the schedule call, you're using %obj. Is something being passed to this function when OnAdd is called? You also list a solo line with %this.schedule(), but unless %this exists within a namespace or function where %this is actually an object that can call the function, that won't work. It seems that you're having some trouble figuring out where %this works? I ask because I'm seeing some errors in the scripting here that indicate that some of these problems aren't being picked up due to inexperience with scripting. If that's the case, that's fine, but it should be said up front so you can be directed to the proper tutorials for this stuff. Scripting can be hard to learn in the begining, especially if you have no prior coding experience. Your profile doesn't list any coding skills, so I have to assume that you're just starting out with this. Am I correct?
#6
12/29/2008 (5:28 pm)
Well i've been using torque about a year. but i've learnt off the forums mostly, me and the tuts on gg dont see eye to eye.
#7
12/29/2008 (5:32 pm)
LOL... Well, there's also Ed Maurina's books. The Game Programmer's Guide To Torque is pretty good for starting out with scripting, even if you're not just starting out with scripting :)
#8
12/30/2008 (8:12 am)
Got both of them but i cant see much to help me with this situation. anyone got examples of a blinkign light?
#9
01/01/2009 (3:56 pm)
Bump plz
#10
01/03/2009 (9:59 am)
No one knows how to make a blinking light?
#11
01/03/2009 (11:28 am)
OK, this tested just fine for me...

I created a sgLightObject in my mission and named it blinkingLight and assigned it the CottageLight datablock.

Then I create a script called lightBlinker.cs and made sure it was executed from my client/init.cs file.

I put the following into lightBlinker.cs:
$blinkRate = 2500;  //Change this to speed up/slow down how fast the light blinks

function blinkLight(%obj)
{
   %db = %obj.getDatablock();
   
   if (%db.LightOn == 0)
   {         
      schedule($blinkRate, 0, blinkOn, %obj);
   }
   else
   {
      schedule($blinkRate, 0, blinkOff, %obj);
   }
}

function blinkOn(%obj)
{
   %db = %obj.getDatablock();
   
   schedule($blinkRate, 0, blinkLight, %obj);  
   //echo("Light on."); 

   %db.LightOn = 1;
}

function blinkOff(%obj)
{
   %db = %obj.getDatablock();
   
   schedule($blinkRate, 0, blinkLight, %obj);
   //echo("Light off.");

   %db.LightOn = 0;
}
Then from the console, I called:
blinkLight(blinkingLight);
...and it worked just fine.

Note that the CottageLight datablock does not allow for the user to see the actual light source, only the light cast from it, so look at the area around the light and you will see that it is blinking. Also, this changes the CottageLight datablock, so all lights that use this would be affected. The easiest solution would be to copy the CottageLight to a new datablock (blinkingLightDatablock) and use that.

Sorry, I don't have time right now to look into making the light volumetric, although it's probably pretty simple.

Best,
Patrick
#12
01/03/2009 (1:35 pm)
Thanks will try that, can i make an sg datablock like an fxlight datablock?
also can i call from another script to run auto with obj.blinkingLight()
#13
01/03/2009 (2:13 pm)
Doesnt seem to work

==>blinkLight(blinkingLight);
(0): Unable to find function blinkLight

i exec'd blinking light in client init
#14
01/03/2009 (2:21 pm)
Quote:Thanks will try that, can i make an sg datablock like an fxlight datablock?
That depends on how you're creating the fxlight datablock but you shouldn't have a problem. You could copy an fxlight datablock, just check the documentation to make sure it has the LightOn parameter inlcuded in it.

Quote:also can i call from another script to run auto with obj.blinkingLight()
No, but you can call blinkLight(LIGHTNAME) from anywhere. Since %obj is a local variable, it only exists in the function it was created in; in this case blinkLight(%obj), that's why we have to pass it to the blinkOn/blinkOff functions.

Quote:
Doesnt seem to work

==>blinkLight(blinkingLight);
(0): Unable to find function blinkLight

i exec'd blinking light in client init
How did you execute lightBlinker.cs?
Are you sure you created a light in your mission and actually named it blinkingLight?
#15
01/03/2009 (2:37 pm)
Exec("./Urban/server/scripts/lightBlinker.cs"); in client init
#16
01/03/2009 (2:50 pm)
I added you to msn if your around