Triggers
by Josiah Trumpower · in Torque Game Engine Advanced · 11/06/2009 (12:50 am) · 15 replies
I want to make a trigger go away after it is activated. Meaning i want it to be only triggered once and never be triggered again until the mission is reloaded. How can I make this happen?
About the author
#2
11/06/2009 (2:00 am)
yaaaaa, I am novice enough to not know what you mean exactly.
#3
11/13/2009 (1:17 am)
Bump
#4
If it doesn't have an "off" value - because one has never been set, it will fire, and then give itself turn it's "off" value to true.
Next time a player walks into it, it'll check it's "off" value, see it has one and not work.
It's a case of if/else. Read the docs online about basic scripting - it'll help.
11/13/2009 (1:35 pm)
Make a little script where the trigger first checks whether it has a value for "off". If it doesn't have an "off" value - because one has never been set, it will fire, and then give itself turn it's "off" value to true.
Next time a player walks into it, it'll check it's "off" value, see it has one and not work.
It's a case of if/else. Read the docs online about basic scripting - it'll help.
#5
datablock TriggerData(Collins_One)
{
tickPeriodMS = 500;
};
datablock SFXProfile(Collins1HUD)
{
fileName = "~/data/sound/collins1HUD";
description = AudioClose3d;
preload = true;
};
function Collins_One::onEnterTrigger(%this,%trigger,%obj)
{
%checkclass = %obj.getclassname();
if(%checkclass $= "player")
{
echo("Player in Trigger");
}
else
{
echo("NOT player in trigger");
}
Parent::onEnterTrigger(%this,%trigger,%obj);
serverPlay3D(Collins1HUD,%obj.getTransform());
}
Thanks :)
11/16/2009 (7:43 pm)
Is it possible for you to post a script for that as an example? Or just take this script I have and alter it to work that way?datablock TriggerData(Collins_One)
{
tickPeriodMS = 500;
};
datablock SFXProfile(Collins1HUD)
{
fileName = "~/data/sound/collins1HUD";
description = AudioClose3d;
preload = true;
};
function Collins_One::onEnterTrigger(%this,%trigger,%obj)
{
%checkclass = %obj.getclassname();
if(%checkclass $= "player")
{
echo("Player in Trigger");
}
else
{
echo("NOT player in trigger");
}
Parent::onEnterTrigger(%this,%trigger,%obj);
serverPlay3D(Collins1HUD,%obj.getTransform());
}
Thanks :)
#6
11/16/2009 (7:48 pm)
I have tried multiple things to make it work. One of which was to delete the trigger after entering it. For some reason when the %trigger.delete(); is called it crashes the game. I have no idea why. I even tried to set hidden %trigger.sethidden(true); and yet again it crashes the game. I have no idea why this happens. Can anyone shed some light.
#7
11/16/2009 (8:01 pm)
Try something like this:function Collins_One::onEnterTrigger(%this, %trigger, %obj)
{
if (%obj.getclassname() $= "player" && !%trigger.doneOnce)
{
echo("Player in Trigger");
%trigger.doneOnce = true;
//Do something else here
}
else
{
echo("NOT player in trigger");
}
Parent::onEnterTrigger(%this, %trigger, %obj);
serverPlay3D(Collins1HUD, %obj.getTransform());
}
#8
11/16/2009 (8:11 pm)
Doing this from memory...function Collins_One::onEnterTrigger(%this,%trigger,%obj)
{
if(%trigger.disable == 0)
{
//trigger must be on - do something below
%checkclass = %obj.getclassname();
if(%checkclass $= "player")
{
//*************this is where the magic happens***********
echo("Player in Trigger");
serverPlay3D(Collins1HUD,%obj.getTransform());
//trigger is doing something -> now to turn it off for next use
%trigger.disable =1;
}
else
{
echo("NOT player in trigger");
//nothing happening here
}
}
else
{
echo("Trigger is off - nothing happens");
}
Parent::onEnterTrigger(%this,%trigger,%obj);
}
#9
%trigger.onMissionEnd(%trigger.disable = 0);
but it just plays the sound over and over again as if I had not stopped it in the first place. I put this code right under where it changes the disabled to 1. Maybe I just put it in the wrong place. I don't know, sorry for asking for so much help.
11/17/2009 (2:28 pm)
Thanks Steve, just one problem. I did just that but in a different way one time and the same result was had. It saves the number you changed it to and the next time you load the same map it will think that it is a 1 and won't play. I was experimenting but could not find out how to reset the number to 1 on mission end. can you post the reset script? I tried to use%trigger.onMissionEnd(%trigger.disable = 0);
but it just plays the sound over and over again as if I had not stopped it in the first place. I put this code right under where it changes the disabled to 1. Maybe I just put it in the wrong place. I don't know, sorry for asking for so much help.
#10
11/17/2009 (2:29 pm)
Another question, how do you put your code into that format on the forum?
#11
As for the trigger, try calling it's name collins_one, and it might be better to use it on startup of a mission to reset than on a quit.
11/17/2009 (5:13 pm)
For code tags -> click the markuplute link.As for the trigger, try calling it's name collins_one, and it might be better to use it on startup of a mission to reset than on a quit.
#12
Well I did this
but this doesn't work either. The sound just keeps on playing over and over wen stepped on. It apparently cancels out the disable part of the code.
11/17/2009 (9:12 pm)
Oh OK, just like when making a website. Well I did this
datablock TriggerData(Collins_One)
{
tickPeriodMS = 500;
};
datablock SFXProfile(Collins1HUD)
{
fileName = "~/data/sound/collins1HUD";
description = AudioClose3d;
preload = true;
};
function Collins_One::onEnterTrigger(%this,%trigger,%obj)
{
if(%trigger.disable == 0)
{
//trigger must be on - do something below
%checkclass = %obj.getclassname();
if(%checkclass $= "player")
{
//*************this is where the magic happens***********
echo("Player in Trigger");
serverPlay3D(Collins1HUD,%obj.getTransform());
//trigger is doing something -> now to turn it off for next use
%trigger.disable =1;
%Collins_One.onMissionStart(%trigger.disable = 0);
}
else
{
echo("NOT player in trigger");
//nothing happening here
}
}
else
{
echo("Trigger is off - nothing happens");
}
Parent::onEnterTrigger(%this,%trigger,%obj);
}but this doesn't work either. The sound just keeps on playing over and over wen stepped on. It apparently cancels out the disable part of the code.
#13
Does the trigger's .disable value change when you step into it?
Try inverting the checkclass into a !$="player" and swap the 2 section around else to reflect this, get it to choose a negative first before a positive.
Also check out the scripting doc on if/else/return/continue functions.
11/17/2009 (10:37 pm)
onStartMission won't work from a trigger - surely it's a game connection function and needs to be used at connection time.Does the trigger's .disable value change when you step into it?
Try inverting the checkclass into a !$="player" and swap the 2 section around else to reflect this, get it to choose a negative first before a positive.
Also check out the scripting doc on if/else/return/continue functions.
#14
11/18/2009 (6:43 pm)
yes the trigger value changes. But never resets back to zero. Even when exiting the game. So it will never be triggered again. But that s not what I want. I want it to play only once in a mission and then again when the mission is reloaded and so on. I tried to reverse it, the negative to positive thing, and it didn't work either.
#15
11/20/2009 (12:14 am)
However, @Twisted I tried the code you gave me and it didn't work the first time. But I changed it a little bit, it didn't like the play sound call under the parent trigger option. So I changed it to this and it worked perfectly, thanks!function Collins_One::onEnterTrigger(%this, %trigger, %obj)
{
if (%obj.getclassname() $= "player" && !%trigger.doneOnce)
{
echo("Player in Trigger");
%trigger.doneOnce = true;
serverPlay3D(Collins1HUD, %obj.getTransform());
//Do something else here
}
else
{
echo("NOT player in trigger");
}
Parent::onEnterTrigger(%this, %trigger, %obj);
}
Associate Scott Burns
GG Alumni
Another would be to add a dynamicField to your trigger to take the place of that global bool. I was actually experimenting with this method earlier today myself.