bindCmd & getWord
by John Roberts · in Torque Game Builder · 06/05/2010 (7:45 am) · 3 replies
Hello all.
I am attempting to edit part of a behavior for a small game I'm working on, in the science-fiction vein. The behavior creates a keybind, which allows an object (the player's spaceship) to fire a set of laser turrets.
The keybind function already works quite well, but I am attempting to make it a little more flexible. As shown below, it performs perfectly:
moveMap.bindCmd(keyboard, "s", "Player.FireLaser();", "Player.StopLaser();");
The above code lets me call a function both when the "s" key is pressed, and also when it is released.
However, if I want to change the key that controls these functions, I have to go back to the code, instead of changing it within the GUI via a behaviorField, like so:
%template.addBehaviorField(FireKey, "Key that fires the laser.", keybind, "keyboard S");
My problem, and my question, is this: is there a way to edit the bindCmd function so that it will recognize the key chosen by the behaviorField? I have made a few attempts using getWord, but to no avail.
Does anyone have a thought?
I am attempting to edit part of a behavior for a small game I'm working on, in the science-fiction vein. The behavior creates a keybind, which allows an object (the player's spaceship) to fire a set of laser turrets.
The keybind function already works quite well, but I am attempting to make it a little more flexible. As shown below, it performs perfectly:
moveMap.bindCmd(keyboard, "s", "Player.FireLaser();", "Player.StopLaser();");
The above code lets me call a function both when the "s" key is pressed, and also when it is released.
However, if I want to change the key that controls these functions, I have to go back to the code, instead of changing it within the GUI via a behaviorField, like so:
%template.addBehaviorField(FireKey, "Key that fires the laser.", keybind, "keyboard S");
My problem, and my question, is this: is there a way to edit the bindCmd function so that it will recognize the key chosen by the behaviorField? I have made a few attempts using getWord, but to no avail.
Does anyone have a thought?
About the author
An aspiring game designer with little programming experience - looking to live and learn.
Recent Threads
#2
I could have sworn I had already attempted what you've shown me, but it didn't work properly that time around.
Another case of code being just a character off, I suppose.
Nevertheless, thank you very much! This was exactly what I needed.
06/05/2010 (2:42 pm)
?I could have sworn I had already attempted what you've shown me, but it didn't work properly that time around.
Another case of code being just a character off, I suppose.
Nevertheless, thank you very much! This was exactly what I needed.
#3
06/05/2010 (7:06 pm)
Happy to help.
Torque Owner RollerJesus
Dream. Build. Repeat.
The generic input behavior on tdn has what you're looking for.
So to adapt it to you example, you would do this:
//----------------------------------------------------------------------------- // Torque Game Builder // Copyright (C) GarageGames.com, Inc. //----------------------------------------------------------------------------- if (!isObject(GenericInputActionBehavior)) { %template = new BehaviorTemplate(GenericInputActionBehavior); %template.friendlyName = "Freaking laser beam firer"; %template.behaviorType = "Input"; %template.description = "Fires a freaking laser beam"; %template.addBehaviorField(FireKey, "Key that fires the laser.", keybind, "S"); } function GenericInputActionBehavior::onAddToScene(%this, %scenegraph) { if (!isObject(moveMap)) return; moveMap.bindCmd(getWord(%this.FireKey, 0), getWord(%this.FireKey, 1), "Player.FireLaser();", "Player.StopLaser();"); }I didn't test this but it should work.