How to stop a behavior?
by Ryan Jones · in Torque Game Builder · 12/26/2008 (9:14 pm) · 5 replies
I've been messing with my intro screen and to start the game you press Enter. Upon pressing enter it runs a function with links to a couple of other functions and does some fancy animations and then moves on to the next scene. I'm using the genericInputAction behavior.
actionkey = enter
command = startaction
What I'm asking is what's the easiest way to make it so that once a person pushes Enter once it will initialize my fucntion, but make it so he can't hit Enter again to reinitilize the behavior in the middle of it doing it's thing.
actionkey = enter
command = startaction
if (!isObject(GenericInputActionBehavior))
{
%template = new BehaviorTemplate(GenericInputActionBehavior);
%template.friendlyName = "Generic Input Action";
%template.behaviorType = "Input";
%template.description = "Executes a command when the specified key is pressed";
%template.addBehaviorField(actionKey, "The key that triggers the command", keybind, "keyboard enter");
%template.addBehaviorField(command, "The Torque Script function to call", string, "");
}
function GenericInputActionBehavior::onAddToScene(%this, %scenegraph)
{
if (!isObject(moveMap))
return;
moveMap.bind(getWord(%this.actionKey, 0), getWord(%this.actionKey, 1), %this.command);
}What I'm asking is what's the easiest way to make it so that once a person pushes Enter once it will initialize my fucntion, but make it so he can't hit Enter again to reinitilize the behavior in the middle of it doing it's thing.
About the author
Creator and project manager of Lightsire Entertainment. http://www.lightsire.com
#2
I notice there's a callback called onBehaviorRemove(), does that mean there's a way to dynamically remove a behavior? In theory that should work too.
12/29/2008 (7:10 pm)
I'll give it a try, I'm hoping that works because it's such an oversight that needs to be fixed.I notice there's a callback called onBehaviorRemove(), does that mean there's a way to dynamically remove a behavior? In theory that should work too.
#3
removeBehavior(BehaviorInstance bi,[bool deleteBehavior=true])
Params:
bi: The behavior instance to remove
deleteBehavior: Whether or not to delete the behavior
Return: bool
success: Whether the behavior was successfully removed
So you can remove it choosing to delete the behavior instance or not.
If you mean an oversight in the engine then I don't follow. What was suggested by Brian seems like the ideal way to do it, handle it via your own game logic. That or by removing the behavior, which you will have to do via your own game logic as well, so either way it will probably take about the same amount of work and the power is in your hands, which is where it should be :)
12/30/2008 (10:09 am)
Well after a quick look in Reference -> TGB Reference -> Behavior Component here is the description of removeBehavior (this is in the docs included with your install, go to Help->Documentation in the tool to get there)removeBehavior(BehaviorInstance bi,[bool deleteBehavior=true])
Params:
bi: The behavior instance to remove
deleteBehavior: Whether or not to delete the behavior
Return: bool
success: Whether the behavior was successfully removed
So you can remove it choosing to delete the behavior instance or not.
Quote:I'll give it a try, I'm hoping that works because it's such an oversight that needs to be fixed.
If you mean an oversight in the engine then I don't follow. What was suggested by Brian seems like the ideal way to do it, handle it via your own game logic. That or by removing the behavior, which you will have to do via your own game logic as well, so either way it will probably take about the same amount of work and the power is in your hands, which is where it should be :)
#4
12/30/2008 (5:53 pm)
Oh no no! Sorry! Not an oversight of the engine, an oversight by me! Engine fine, it's the user right now.
#5
Also, Brian's solution did work, yay.
For some reason I couldn't use %this, I had to use the object's specific name of the scene.
01/02/2009 (2:57 pm)
Quick question, is there a way to immediately disable keyboard input in TGB 1.7.4? I saw in some of the older tutorials you could just use playerMap.pop() but that does not work seem to work in this current version of TGB.Also, Brian's solution did work, yay.
function GenericInputActionBehavior::onAddToScene(%this, %scenegraph)
{
if (!isObject(moveMap))
return;
Flash.control = 1;
moveMap.bind(getWord(%this.actionKey, 0), getWord(%this.actionKey, 1), %this.command);
}
function fire(%this, %scenegraph)
{
if (Flash.control == 0)
return;
Flash.control = 0;
...someting here...
}For some reason I couldn't use %this, I had to use the object's specific name of the scene.
Torque Owner Brian Wilson
moveMap.bind(keyboard, "enter", "action"); function action(%val) { if(%val) { if($enter.disabled) return; else { $enter.disabled = 1; ...do stuff... } }