Ridiculous Trigger Problem
by Alessandro Loureiro · in Technical Issues · 09/16/2005 (8:05 pm) · 5 replies
All right, people... I'm deseperate. Trigger SIMPLE doesn't work.
It's that simple flag tutorial that SHOULD work! I obviously doing something wrong, but trust me, i'm only seeking help here after MUCH struggle!
I'm still in early development steps of my game characteristics, and i don't plan to change Torque "tribes" aspects much. I'm working now on simple triggers events.
The thing was on the flagpole tutorial with a trigger. Done so far:
-Created a nameless group inside the game tree where both trigger and flag shape stays;
- Flagpole has its animation working perfectly. Checked in SHOWTOOL, and i use the same .dts on a datablock that runs its animation ciclic in the game (with the ::onAdd instead of the ::onTrigger)
Ok, more clearly:
I have a FLAGPOLE.CS with:
works perfectly. But when i use FLAGPOLE2.CS:
...doesn't work...
Just to be sure, this is the trigger's datablock:
the console.log doesn't show no typing errors. The trigger works- i had put an echo inside the trigger and it shows up on console.log -but still, the flag doesn't accept the trigger contact... my character walks on the trigger and the flag doesn't animate!
I'm using the same .dts on FLAG2 and Flag... i'm keeping then both on the scene... but i know that's not the problem...(i changed it to the jumping_ball.dts and nothing changed).
Ah, before i forgot: both FLAGPOLE.CS and FLAGPOLE2.CS are being called in the game.cs by exec statement, so is not that either...
Any tip, anyone? Any help will be apreciated.
Thanks in advance,
Eric Morata
It's that simple flag tutorial that SHOULD work! I obviously doing something wrong, but trust me, i'm only seeking help here after MUCH struggle!
I'm still in early development steps of my game characteristics, and i don't plan to change Torque "tribes" aspects much. I'm working now on simple triggers events.
The thing was on the flagpole tutorial with a trigger. Done so far:
-Created a nameless group inside the game tree where both trigger and flag shape stays;
- Flagpole has its animation working perfectly. Checked in SHOWTOOL, and i use the same .dts on a datablock that runs its animation ciclic in the game (with the ::onAdd instead of the ::onTrigger)
Ok, more clearly:
I have a FLAGPOLE.CS with:
datablock StaticShapeData(Flag)
{
category = "Misc";
shapeFile = "~/data/shapes/objects/flagpole.dts";
};
function Flag::onAdd(%this,%obj)
{
%obj.playThread(0,"ambient");
}works perfectly. But when i use FLAGPOLE2.CS:
datablock StaticShapeData(FLAG2)
{
category = "Misc";
shapeFile = "~/data/shapes/objects/flagpole.dts";
};
function FLAG2::onTrigger(%this, %obj, %state)
{
echo("trigger has just activated flag2.");
if(%state == 1)
{
%obj.playThread(0);
}
else if(%state == 0)
{
%obj.stopThread(0);
}
}...doesn't work...
Just to be sure, this is the trigger's datablock:
datablock TriggerData(FLAG2_trigger)
{
tickPeriodMS = 100;
};
function FLAG2_trigger::onEnterTrigger(%this,%trigger,%obj)
{
echo("Eric: FLAG2_trigger= INICIANDO...");
Parent::onEnterTrigger(%this,%trigger,%obj);
}the console.log doesn't show no typing errors. The trigger works- i had put an echo inside the trigger and it shows up on console.log -but still, the flag doesn't accept the trigger contact... my character walks on the trigger and the flag doesn't animate!
I'm using the same .dts on FLAG2 and Flag... i'm keeping then both on the scene... but i know that's not the problem...(i changed it to the jumping_ball.dts and nothing changed).
Ah, before i forgot: both FLAGPOLE.CS and FLAGPOLE2.CS are being called in the game.cs by exec statement, so is not that either...
Any tip, anyone? Any help will be apreciated.
Thanks in advance,
Eric Morata
#2
You are the king today. I have been struggling with
the same thing and have had exactly the same problem.
Just by adding
my problem is solved.
My hat off for you...
Many thanks
09/17/2005 (7:02 am)
Eric Mostata Baptista:You are the king today. I have been struggling with
the same thing and have had exactly the same problem.
Just by adding
function StaticShape::onTrigger(%this, %obj, %state)
{
%this.getDatablock().onTrigger(%this, %state);
}my problem is solved.
My hat off for you...
Many thanks
#3
There is also setThreadDir(slot,true/false) this one you use if you want to reverse the animation when you played it once , can be used for doors ,switches and more.
09/17/2005 (8:52 am)
Some info for the playThread , the syntax is PlayThread(slot,"Sequencename") to start it, and to stop the animation you use StopThread(slot) like you did above.There is also setThreadDir(slot,true/false) this one you use if you want to reverse the animation when you played it once , can be used for doors ,switches and more.
#4
i think the reason it may be listed as optional is because for simple triggers you dont really need to implement it using the ontrigger method. when an object enters the trigger, the onentertrigger method is called automatically. whatever you want to happen can be implemented directly in there:
function FLAG2_trigger::onEnterTrigger(%this,%trigger,%obj)
{
%obj.playThread(0,"ambient");
}
this will work even if this animation doesnt exist in the object.
also, in general, all of the shapebase animation functions take the
animation index as the only parameter. the only exception is playthread(0,"ambient") which takes an index and an animation name.
09/17/2005 (11:24 am)
"There is an override kind of a function that makes the object feel the trigger with ::onTrigger statement. Its listed as optional, but its actually a must-have!"i think the reason it may be listed as optional is because for simple triggers you dont really need to implement it using the ontrigger method. when an object enters the trigger, the onentertrigger method is called automatically. whatever you want to happen can be implemented directly in there:
function FLAG2_trigger::onEnterTrigger(%this,%trigger,%obj)
{
%obj.playThread(0,"ambient");
}
this will work even if this animation doesnt exist in the object.
also, in general, all of the shapebase animation functions take the
animation index as the only parameter. the only exception is playthread(0,"ambient") which takes an index and an animation name.
#5
Im glad that, bit by bit, all Torque problems and limitations are being dispelled by the forums. Thing is, most Torque code asks for repeated atempts even for tutorial examples... get this:
I just fast-modeled a windmill-like water-weel dts for the scenario to test the ciclic animation code; it works but kinda lacked some water and moist effects in the planks, so i checked the modeling tutorial saying that BB::shapename would give billboard effects for sub-shapes in the model,with that some could model the moist effect with transparent maps! I tryied but finded out that sub-shapes CAN'T be animated... they didn't even show up on the showtool.
Er... right, its something to the modeling 3ds threads, but it's just an example that the tutorials are either imcomplete or Torque has so many aspects that it would be impossible to put everthing in the tutorials.
My think is that the tutorials could have a little upgrade, or maybe Garagegames won't do it until the next version release. Oh well...
Billy, thanks for the setThreadDir(slot,true/false)! Doors where going to be my next step (after action button implementation, peraphs...).
Sean, i may be wrong but i could swear i tryed that! But i think that instead of
%obj.playThread(0,"ambient"); i used Flag2.playThread(0,"ambient");...
SIGH... edit script,save, run game, try playing, turn off, edit script... get crazy, go to the forums... :p
09/17/2005 (7:25 pm)
You're welcome, Roland! :DIm glad that, bit by bit, all Torque problems and limitations are being dispelled by the forums. Thing is, most Torque code asks for repeated atempts even for tutorial examples... get this:
I just fast-modeled a windmill-like water-weel dts for the scenario to test the ciclic animation code; it works but kinda lacked some water and moist effects in the planks, so i checked the modeling tutorial saying that BB::shapename would give billboard effects for sub-shapes in the model,with that some could model the moist effect with transparent maps! I tryied but finded out that sub-shapes CAN'T be animated... they didn't even show up on the showtool.
Er... right, its something to the modeling 3ds threads, but it's just an example that the tutorials are either imcomplete or Torque has so many aspects that it would be impossible to put everthing in the tutorials.
My think is that the tutorials could have a little upgrade, or maybe Garagegames won't do it until the next version release. Oh well...
Billy, thanks for the setThreadDir(slot,true/false)! Doors where going to be my next step (after action button implementation, peraphs...).
Sean, i may be wrong but i could swear i tryed that! But i think that instead of
%obj.playThread(0,"ambient"); i used Flag2.playThread(0,"ambient");...
SIGH... edit script,save, run game, try playing, turn off, edit script... get crazy, go to the forums... :p
Alessandro Loureiro
...and after a lookout on the tutorials i finally solved the puzzle. The tutorial is wrong. There is an override kind of a function that makes the object feel the trigger with ::onTrigger statement. Its listed as optional, but it's actually a must-have!
And worse: in the playthread code," %obj.playThread(0) " doesn't work, but " %obj.playThread(0,"ambient"); " works!
But for some reason, " %obj.stopThread(0,"ambient"); " doesn't work and " %obj.stopThread(0); " works normally...
go figures...
here's the working code, if anyone had the same problem:
SERVER/SCRIPTS/FLAGPOLE.CS :
datablock StaticShapeData(FLAG2) { category = "Misc"; shapeFile = "~/data/shapes/objects/flagpole.dts"; }; function FLAG2::onTrigger(%this, %obj, %state) { echo("FLAG2 DTS IS WORKING"); if(%state == 1) { %obj.playThread(0,"ambient"); //%obj.playThread(0); //doesn't work, for some reason. } else if(%state == 0) { //%obj.stopThread(0,"ambient"); //doesn't work! %obj.stopThread(0); } }SERVER/SCRIPTS/TRIGGER.CS :
datablock TriggerData(FLAG2_trigger) { tickPeriodMS = 100; }; //The next function MUST be in the trigger.cs! wharever the reason, is listed as optional in the tutorial... function StaticShape::onTrigger(%this, %obj, %state) { %this.getDatablock().onTrigger(%this, %state); } function FLAG2_trigger::onEnterTrigger(%this,%trigger,%obj) { echo("FLAG2_trigger has been activated..."); Parent::onEnterTrigger(%this,%trigger,%obj); }I'm looking forward to see if more people had the same problem, because triggers are so essential for scenario interaction that is was weird, i wasn't able to find no thread in the forums about this trigger problem... maybe i didn't looked out correctly...
thanks anyways, guys.