Trigger Behavior and Associated Object
by rennie moffat · in Torque Game Builder · 11/17/2009 (1:51 pm) · 9 replies
Hi there I am working on a trigger code. Following the Rainy Day I have devised a simple design to allow, my BigBlock, to be triggered by my player, Spacer3000. Yet it does not work. If you could see what is wrong, please help thanks.
PS. all items are classed as the classes above and all have collisions turned on.
//behavior of object when triggered
///currently it is a 2 celled animation
///the new animation is a separate sprite all together.
///the other sprite is completely separate. me thinks I will have to put in a "setPosition" when ready.
if (!isObject(BigBlockBeenTriggered))
{
%template = new BehaviorTemplate(BigBlockBeenTriggered);
%template.friendlyName = "BigBlockBeenTriggered";
%template.behaviorType = "BigBlockBeenTriggeredBehavior";
%template.description = "BigBlockBeenTriggered";
}
function BigBlockBeenTriggered::startForward(%this, %animation)
{
%this.animation.playAnimation(%this.forwardAni);
}
function BigBlockBeenTriggered::startBackward(%this, %animation)
{
%this.animation.playAnimation(%this.backwardAni);
}///the trigger's code,
//trigger attached to moveable player.
if (!isObject(Spacer3000BigBlockTrigger))
{
%template = new BehaviorTemplate(Spacer3000BigBlockTrigger);
%template.friendlyName = "Spacer3000 Trigger for BigBlock";
%template.behaviorType = "Trigger";
%template.description = "Defines which/when animation BigBlockPlays";
}
function Spacer3000BigBlockTrigger::onEnter(%this, %object)
{
%object.startForward();
}
function Spacer3000BigBlockTrigger::onLeave(%this, %object)
{
%object.startBackward();
}PS. all items are classed as the classes above and all have collisions turned on.
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
11/18/2009 (10:58 am)
I am sure I am making a very simple error that you ( a vet) can spot instantly. If so, please pass your knowledge on.
#3
I don't know anything about what is your problem, what are startForward(), startPulse(), forwardAni and backwardAni.
I do not mean what you are expected them to be, that part is easy to guess, but what they are as far as your script is concerned...
What I'm pretty sure, though, is that that without knowing exactly what should be doing that part of your code and in which way it doesn't work, it's nearly impossible to instantly spot an error.
It might be a very simple error but it might be a not so simple one. It also might be an error in the startForward function or in the forwardAni value or anything else for that matter.
So as I said before, I can't really help (more than that)...
Oh, and by the way, I'm not a vet so don't take my words for granted ;)
11/18/2009 (11:20 am)
As far as I am concerned, it's hard to help.I don't know anything about what is your problem, what are startForward(), startPulse(), forwardAni and backwardAni.
I do not mean what you are expected them to be, that part is easy to guess, but what they are as far as your script is concerned...
What I'm pretty sure, though, is that that without knowing exactly what should be doing that part of your code and in which way it doesn't work, it's nearly impossible to instantly spot an error.
It might be a very simple error but it might be a not so simple one. It also might be an error in the startForward function or in the forwardAni value or anything else for that matter.
So as I said before, I can't really help (more than that)...
Oh, and by the way, I'm not a vet so don't take my words for granted ;)
#4
hah, thanks. well let me Obama this and let me be clear.
startForward is a function which "should set the animation of an object"
startBackward is a fucntion which should "set the animation of the same object (as above) but to a different animation... which is called backwardAni"
edit, I have edited the code ( i had made a mistake earlier, anyhow, there is no more Pulse, just forward and backward animations. The point is to have a trigger object, set off an animation in a object onEnter and then onLeave.
11/18/2009 (11:50 am)
Oh I'll hold you too that.hah, thanks. well let me Obama this and let me be clear.
startForward is a function which "should set the animation of an object"
startBackward is a fucntion which should "set the animation of the same object (as above) but to a different animation... which is called backwardAni"
edit, I have edited the code ( i had made a mistake earlier, anyhow, there is no more Pulse, just forward and backward animations. The point is to have a trigger object, set off an animation in a object onEnter and then onLeave.
#5
Are your functions startForward and startBackward defined somewhere? I might be wrong but I don't think they are built-in functions of Torque Script.
backwardAni: is it defined somewhere?
11/18/2009 (12:03 pm)
Quote:
I do not mean what you are expected them to be, that part is easy to guess, but what they are as far as your script is concerned...
Are your functions startForward and startBackward defined somewhere? I might be wrong but I don't think they are built-in functions of Torque Script.
backwardAni: is it defined somewhere?
#6
see code above.
but also as actual animations in TGB.
11/18/2009 (12:27 pm)
Yes, they are defined as in script as functions and methods.see code above.
but also as actual animations in TGB.
#7
I'm wondering because startForward and startBackward are defined in BigBlockBeenTriggered scope but called in Spacer3000BigBlockTrigger scope...
Probably something about behavious that I'm not understanding so bear with me and feel free to point out both my newbiness and why my wondering is false (which might very well be the case) ;)
11/18/2009 (1:00 pm)
Ok, I'm definitely not a pro of behaviors (major understatement), but I'm not sure to see how "BigBlockBeenTriggered" and "Spacer3000BigBlockTrigger" are linked together.I'm wondering because startForward and startBackward are defined in BigBlockBeenTriggered scope but called in Spacer3000BigBlockTrigger scope...
Probably something about behavious that I'm not understanding so bear with me and feel free to point out both my newbiness and why my wondering is false (which might very well be the case) ;)
#8
Upon doing so, the big Block will change its animation state. When the hero leaves, the animation state of BigBlock changes back to its original state.
I have created the BigBlockBeenTriggered and attached it to the bigBlock as this is supposed to house what happens to bigBlock when the Spacer3000 "goes over him".
The Spacer3000BigBlockTrigger is attached to the a TRIGGER object, which is mounted to my movable hero. The trigger, I would think should send the function, or call for the method of the startForward, startBackward on onEnter and onLeave conditions.
This Does worry me slightly since the startForward and startBackward functions, first called, onEnter or onLeave in the Spacer3000BigBlockTrigger.cs and the actual function of startForward, saying playAnimation () is in the bigBlockBeenTriggered.cs
I am not sure if this is right, or possible. I have classed the objects as the behavior Tttles.
11/18/2009 (1:10 pm)
ok well, what I am trying to do is have my hero, simply "rollOver" "enter", "go on top of" the bigBlock.Upon doing so, the big Block will change its animation state. When the hero leaves, the animation state of BigBlock changes back to its original state.
I have created the BigBlockBeenTriggered and attached it to the bigBlock as this is supposed to house what happens to bigBlock when the Spacer3000 "goes over him".
The Spacer3000BigBlockTrigger is attached to the a TRIGGER object, which is mounted to my movable hero. The trigger, I would think should send the function, or call for the method of the startForward, startBackward on onEnter and onLeave conditions.
This Does worry me slightly since the startForward and startBackward functions, first called, onEnter or onLeave in the Spacer3000BigBlockTrigger.cs and the actual function of startForward, saying playAnimation () is in the bigBlockBeenTriggered.cs
I am not sure if this is right, or possible. I have classed the objects as the behavior Tttles.
Torque Owner rennie moffat
Renman3000