TickTrigger consistently updates player's parameters
by c-level · in Torque Game Engine · 09/17/2003 (4:38 pm) · 15 replies
I have these areas in my game that when a player hangs out there, their health gradually increases. (It's not actually health, but more like mana. You get the idea).
So I've created a trigger, and it's quite easy to give the player health when he's entering or exiting the trigger. I figured tickTrigger would be great for consistently giving health, but that function has no %obj passed in, so
...there is no %obj for me to check and access the player
I thought about creating a recursive schedule when they enter that increases health every second. Then I'd cancel that schedule when they exit, but that seems goofy. I would very much have to trust that schedule being cancelled or that player is going to have an easy time for the rest of the game ;)
--
This in theory goes for damage. I've created these patches of fire with particlesEmitter.cs. It looks great, but I want the player to perpetually get damaged while standing in it. I was planning to use triggers in the same way.
What would you guys do?
Thanks
So I've created a trigger, and it's quite easy to give the player health when he's entering or exiting the trigger. I figured tickTrigger would be great for consistently giving health, but that function has no %obj passed in, so
function TriggerHealth::onEnterTrigger(%this,%trigger,%obj)
{
Parent::onEnterTrigger(%this,%trigger,%obj);
if (%obj.aiPlayer != true) {
//increase health
}
}... but infunction TriggerHealth::onTickTrigger(%this,%trigger)
{
}...there is no %obj for me to check and access the player
I thought about creating a recursive schedule when they enter that increases health every second. Then I'd cancel that schedule when they exit, but that seems goofy. I would very much have to trust that schedule being cancelled or that player is going to have an easy time for the rest of the game ;)
--
This in theory goes for damage. I've created these patches of fire with particlesEmitter.cs. It looks great, but I want the player to perpetually get damaged while standing in it. I was planning to use triggers in the same way.
What would you guys do?
Thanks
About the author
#2
an echo statement shows me that %trigger has a 4 digit number associated with it, but I don't know what to do with it.
I tried things with the provided commented code:
%n = %trigger.getNumObjects();
%trigger.getObject(%n);
....and all kinds of combinations of such that include a for loop checking all numbers produced with .getNumObjects().
I even tried
function Player::onTickTrigger(){
}
...because I'm lost. I'm not a C++ person. Is that the problem?
just in case I'm creating it incorrectly, Here's how I spawn it.
I'm happy tinkering with it, so any hint would be great.
Thanks
09/17/2003 (8:09 pm)
Shoot. I feel like I'm stuck on something simple. All forum searches find very few threads concerning onTickTrigger. an echo statement shows me that %trigger has a 4 digit number associated with it, but I don't know what to do with it.
I tried things with the provided commented code:
%n = %trigger.getNumObjects();
%trigger.getObject(%n);
....and all kinds of combinations of such that include a for loop checking all numbers produced with .getNumObjects().
I even tried
function Player::onTickTrigger(){
}
...because I'm lost. I'm not a C++ person. Is that the problem?
just in case I'm creating it incorrectly, Here's how I spawn it.
%thetrigger = new Trigger() {
position = " 0 0 0";
scale = "5 5 5";
datablock = "triggerHealth";
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
};I'm happy tinkering with it, so any hint would be great.
Thanks
#3
for(%i = 0; %i < %trigger.getNumObjects();%i++)
{
%trigger.getObject(%i).client.incScore(1);
}
//which increases the score of all of the players in the trigger
//per tick.
I hope that helps.
09/17/2003 (9:31 pm)
I get access to the player etc in triggers by this (in onTickTrigger):for(%i = 0; %i < %trigger.getNumObjects();%i++)
{
%trigger.getObject(%i).client.incScore(1);
}
//which increases the score of all of the players in the trigger
//per tick.
I hope that helps.
#4
The value for %trigger.getNumObjects() works perfectly. It updates as players and aiplayers move in and out.
But I get '-1' for %trigger.getObject(%index) regarless if the objects are aiPlayer or Player.
I access my players and aiplayers all the time (like in 'onEnterTrigger') so it's no surprise that I get no value for
What does getting '-1' tell you?
And how can it correctly tell me how many object are in the trigger, but be unable to identify the objects?
I even went back to the original file 'triggers.cs' and used defaultTrigger. I have just one trigger in my world. Same. I must be doing something stupid.
Thanks again
09/17/2003 (10:13 pm)
Yeah, when I try...%n = %trigger.getNumObjects();
echo("n = " @ %n);
for( %index = 0; %index < %n; %index++ ) {
echo("the objects = " @ %trigger.getObject(%index));
}The value for %trigger.getNumObjects() works perfectly. It updates as players and aiplayers move in and out.
But I get '-1' for %trigger.getObject(%index) regarless if the objects are aiPlayer or Player.
I access my players and aiplayers all the time (like in 'onEnterTrigger') so it's no surprise that I get no value for
%trigger.getObject(%index).client
What does getting '-1' tell you?
And how can it correctly tell me how many object are in the trigger, but be unable to identify the objects?
I even went back to the original file 'triggers.cs' and used defaultTrigger. I have just one trigger in my world. Same. I must be doing something stupid.
Thanks again
#5
do you have this in it?
Parent::onTickTrigger( %this, %trigger );
mine worked without it but still...
I tried your loop etc and everything turnd out nicely.
so your onTickTrigger looks like:
function triggerHealth::onTickTrigger( %this, %trigger)
{
Parent::onTickTrigger( %this, %trigger );
%n = %trigger.getNumObjects();
echo("n = " @ %n);
for( %index = 0; %index < %n; %index++ )
{
echo("the objects = " @ %trigger.getObject(%index));
}
}
Is this a stock engine? which release?
Ahm I can't really think of why it doesn't work.
09/17/2003 (10:46 pm)
Well this seems odd.do you have this in it?
Parent::onTickTrigger( %this, %trigger );
mine worked without it but still...
I tried your loop etc and everything turnd out nicely.
so your onTickTrigger looks like:
function triggerHealth::onTickTrigger( %this, %trigger)
{
Parent::onTickTrigger( %this, %trigger );
%n = %trigger.getNumObjects();
echo("n = " @ %n);
for( %index = 0; %index < %n; %index++ )
{
echo("the objects = " @ %trigger.getObject(%index));
}
}
Is this a stock engine? which release?
Ahm I can't really think of why it doesn't work.
#6
And I downloaded Torque again and placed that simple for loop in 'triggers.cs'. No other changes. Same.
I guess I have to move on.
Am I supposed to have the HEAD version?
Thanks
**I should post this somewhere else, but when I download Torque with WinCVS, I follow the very specific instructions to get Release 1.1.2, and as it's downloading, it confirms it. I did it yesterday because of your question about my release version. I even got a friend today to follow the instructions as I silently watched him. But after I compile, and I click 'About...' at the start menu, it says 1.1.1. I tried downloading 1.1.1 intentionally and saw that the console contains echo messages that I've never seen and other differences like the text in the LOADING bar is green instead of black. Also, I've incorporated resources that say that you have version 1.1.2 with no problems. So I believe I've always has version 1.1.2.**
09/18/2003 (11:44 am)
That's what I did. I tried spawning the trigger both in code and in the world editor. In and outside of my interiors. I used the original trigger.cs. Then I went back to the backup of Torque I had from my original download months ago. Same. And I downloaded Torque again and placed that simple for loop in 'triggers.cs'. No other changes. Same.
I guess I have to move on.
Am I supposed to have the HEAD version?
Thanks
**I should post this somewhere else, but when I download Torque with WinCVS, I follow the very specific instructions to get Release 1.1.2, and as it's downloading, it confirms it. I did it yesterday because of your question about my release version. I even got a friend today to follow the instructions as I silently watched him. But after I compile, and I click 'About...' at the start menu, it says 1.1.1. I tried downloading 1.1.1 intentionally and saw that the console contains echo messages that I've never seen and other differences like the text in the LOADING bar is green instead of black. Also, I've incorporated resources that say that you have version 1.1.2 with no problems. So I believe I've always has version 1.1.2.**
#7
have a look at the ctf code snipit its called something like flag and code etc. It has triggers used in that, may help find your defect.
**
HEAD version isn't meant to be as stable so it was for that reason I asked
**
09/20/2003 (7:00 am)
Ok release should really matter I think if you want HEAD, just put in no branch and it'll get the HEAD automaticaly.have a look at the ctf code snipit its called something like flag and code etc. It has triggers used in that, may help find your defect.
**
HEAD version isn't meant to be as stable so it was for that reason I asked
**
#8
have a look at the ctf code snipit its called something like flag and code etc. It has triggers used in that, may help find your defect.
**
HEAD version isn't meant to be as stable so it was for that reason I asked
**
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2799
^
thats the ctf code snipit.
09/20/2003 (7:06 am)
Ok release should really matter I think if you want HEAD, just put in no branch and it'll get the HEAD automaticaly.have a look at the ctf code snipit its called something like flag and code etc. It has triggers used in that, may help find your defect.
**
HEAD version isn't meant to be as stable so it was for that reason I asked
**
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2799
^
thats the ctf code snipit.
#9
I read through this tutorial (although I haven't done it yet) and I don't see any use of 'onTickTrigger'. They use 'onEnterTrigger' which I find great because '%obj' is passed in. 'onEnterTrigger' and 'onLeaveTrigger' are the two functions that I call always ask, Who just entered or left? Being able to ask, Who is standing in the trigger? would be great. Since I can't get it to work in my original download of Torque, then I can rule out any destructive tinkering on my part. Am I missing anything?
I wish I could change the source so that '%obj' can be passed in 'onTickTrigger'. Maybe that could be my first C++ task. But I realize that there must be a good reason why it's not already implemented. What do you think?
So you know, I've come up a crazy backup plan. When the player enters the trigger, 'onEnterTrigger' starts a recursive schedule that calls every second. When they leave the schedule is cancelled. I have an additional distance check in case 'onLeaveTrigger' somehow doesn't get called. But such clunky code is worrysome, both because it's ugly and because it doesn't fit well within the details of my game. (Sometimes triggers are spawned right on top of a player, so 'onEnterTrigger' isn't called).
Thanks
09/21/2003 (10:16 am)
Thanks for your persistant help, by the way.I read through this tutorial (although I haven't done it yet) and I don't see any use of 'onTickTrigger'. They use 'onEnterTrigger' which I find great because '%obj' is passed in. 'onEnterTrigger' and 'onLeaveTrigger' are the two functions that I call always ask, Who just entered or left? Being able to ask, Who is standing in the trigger? would be great. Since I can't get it to work in my original download of Torque, then I can rule out any destructive tinkering on my part. Am I missing anything?
I wish I could change the source so that '%obj' can be passed in 'onTickTrigger'. Maybe that could be my first C++ task. But I realize that there must be a good reason why it's not already implemented. What do you think?
So you know, I've come up a crazy backup plan. When the player enters the trigger, 'onEnterTrigger' starts a recursive schedule that calls every second. When they leave the schedule is cancelled. I have an additional distance check in case 'onLeaveTrigger' somehow doesn't get called. But such clunky code is worrysome, both because it's ugly and because it doesn't fit well within the details of my game. (Sometimes triggers are spawned right on top of a player, so 'onEnterTrigger' isn't called).
Thanks
#10
the method "%trigger.getObject()" returns an %obj. and thats why I should work.
Maybe it was broken in 1.1.2 so try getting a HEAD?
Which you would have to get though CVS.
Until then I really can't see what it maybe.
09/21/2003 (7:57 pm)
Well the reason they didn't implement it is becausethe method "%trigger.getObject()" returns an %obj. and thats why I should work.
Maybe it was broken in 1.1.2 so try getting a HEAD?
Which you would have to get though CVS.
Until then I really can't see what it maybe.
#11
I've been avoiding HEAD because I'm not familiar with 99% of the source, but maybe I'm being too careful?
I tried putting trigger.h and trigger.cc from HEAD into my 1.1.2 engine and then compiled. But there were errors. Is it feasable to integrate the triggers from HEAD into 1.1.2?
Thanks
09/22/2003 (12:04 pm)
In HEAD it works like a darn charm. Yes! I've been avoiding HEAD because I'm not familiar with 99% of the source, but maybe I'm being too careful?
I tried putting trigger.h and trigger.cc from HEAD into my 1.1.2 engine and then compiled. But there were errors. Is it feasable to integrate the triggers from HEAD into 1.1.2?
Thanks
#12
HEAD isn't as bad as they say i think its usually got a few problems but as you know so did 1.1.2.
Its most likely a bad idea to put HEAD .cc and .h files in to older versions and he other way around because lots of inheritance is in the engine and so you in break the link of code and left with things not working right or at all, which is the most likley of the two.
09/23/2003 (1:11 am)
Ah good to hear its working as it should.HEAD isn't as bad as they say i think its usually got a few problems but as you know so did 1.1.2.
Its most likely a bad idea to put HEAD .cc and .h files in to older versions and he other way around because lots of inheritance is in the engine and so you in break the link of code and left with things not working right or at all, which is the most likley of the two.
#13
Thanks for your help, Edward.
09/23/2003 (7:13 pm)
Just for this thread's closure, I'll say that I'm now using the HEAD version. Almost all the .cs scripts I'm using are my from my build in 1.1.2. I'm using the HEAD scripts from the folder 'common'. Overall, my game works the same as it did and I wish I had been using this verison earlier.Thanks for your help, Edward.
#14
09/23/2003 (7:48 pm)
No Problem mate.
#15
datablock TriggerData(KillTrigger)
{
tickPeriodMS = 100;
};
function KillTrigger::OnEnterTrigger(%this,%trigger,%obj) {
echo("the this: " @ %this);
echo("the trigger: " @ %trigger);
echo("the obj: " @ %obj);
%client = %obj.client;
if(!%client)
{
return;
}
%client.player.kill("KillTrigger");
}
function KillTrigger::onTickTrigger(%this, %trigger)
{
echo("the this: " @ %this);
echo("the trigger: " @ %trigger);
%n = %trigger.getNumObjects();
for( %index = 0; %index < %n; %index++ )
{
echo("the obj: " @ %trigger.getObject(%index));
%client = %trigger.getObject(%index).client;
if(%client && %trigger.getObject(%index).getState()!$= "Dead" )
{
%client.player.kill("KillTrigger");
}
}}
and at player.cs add this function
function Player::kill(%this, %damageType)
{
%this.damage(0, %this.getPosition(), 1, %damageType);
}
03/16/2005 (2:14 am)
Add at triggers.cs thisdatablock TriggerData(KillTrigger)
{
tickPeriodMS = 100;
};
function KillTrigger::OnEnterTrigger(%this,%trigger,%obj) {
echo("the this: " @ %this);
echo("the trigger: " @ %trigger);
echo("the obj: " @ %obj);
%client = %obj.client;
if(!%client)
{
return;
}
%client.player.kill("KillTrigger");
}
function KillTrigger::onTickTrigger(%this, %trigger)
{
echo("the this: " @ %this);
echo("the trigger: " @ %trigger);
%n = %trigger.getNumObjects();
for( %index = 0; %index < %n; %index++ )
{
echo("the obj: " @ %trigger.getObject(%index));
%client = %trigger.getObject(%index).client;
if(%client && %trigger.getObject(%index).getState()!$= "Dead" )
{
%client.player.kill("KillTrigger");
}
}}
and at player.cs add this function
function Player::kill(%this, %damageType)
{
%this.damage(0, %this.getPosition(), 1, %damageType);
}
Associate Ben Garney