Trying to activate a button.command from a keypress
by Flybynight Studios · in Torque Game Engine · 07/12/2008 (12:47 pm) · 3 replies
I am doing some more work on a fully dynamic hotbar and I must be having a brainfart or something because this is just totally eluding me.
Currently if a person clicks on a hotbar button with the mouse everything functions perfectly. What I want to do is have keyboard binds (from 1 through 0) so that they can just hit the keyboard number that coresponds to the button they wish to activate. That is also easy enough to do..
Here is the tricky part:
Because the hotbars are being designed to be 100% dynamic (IE anything can be put there from a scripted macro command to an attack to a skill etc..) I need to have a way to call up a variable that checks the buttons variable and then executes that action.
For the purposes of this example I will use my "display world map" function as the item that currently resides on the button I am activating.. When I click the button it activates the map and everything is fine. What I want to do is bind the keypress of the number "1" to activate that same function.
If you take dynamics out of the equation it is very simple to just write a function that activates the map (IE: "Canvas.getContent().Add(worldmap1gui);";) but what I would really like to do is execute the hotbar1button1.command which is "command = "Canvas.getContent().Add(cardmap1gui);";"
Anyone know how to trigger a button.command from a keypress?
Thank you all inadvance.
Currently if a person clicks on a hotbar button with the mouse everything functions perfectly. What I want to do is have keyboard binds (from 1 through 0) so that they can just hit the keyboard number that coresponds to the button they wish to activate. That is also easy enough to do..
Here is the tricky part:
Because the hotbars are being designed to be 100% dynamic (IE anything can be put there from a scripted macro command to an attack to a skill etc..) I need to have a way to call up a variable that checks the buttons variable and then executes that action.
For the purposes of this example I will use my "display world map" function as the item that currently resides on the button I am activating.. When I click the button it activates the map and everything is fine. What I want to do is bind the keypress of the number "1" to activate that same function.
If you take dynamics out of the equation it is very simple to just write a function that activates the map (IE: "Canvas.getContent().Add(worldmap1gui);";) but what I would really like to do is execute the hotbar1button1.command which is "command = "Canvas.getContent().Add(cardmap1gui);";"
Anyone know how to trigger a button.command from a keypress?
Thank you all inadvance.
#2
Saved me a ton Ben. thanks a bunch
07/12/2008 (1:22 pm)
Awesome Ben thanks. TDN is still a very hard place to get effictive data for me. The search engine is really goofy. Or at least my understanding of how it parses is probably goofy. Saved me a ton Ben. thanks a bunch
#3
It will simulate a click on the button including tests for whether the button is active, running any associated "command" and anything else the button might do in the background.
07/14/2008 (5:10 am)
Rather than using Eval, have a look at usinghotBar1Button1.performClick();
It will simulate a click on the button including tests for whether the button is active, running any associated "command" and anything else the button might do in the background.
Torque Owner Ben Versaw
TDN and alot of other great documentation is your friend. I tested the solution and it does work.
Edit: Expanded explanation.
Obviously, you have to bind the action to a key. But you could easily do something like the following.
function generateKeyMap() { moveMap.bindCmd(keyboard, "key", "actionBarBtnOne();", ""); moveMap.bindCmd(keyboard, "key", "actionBarBtnTwo();", ""); // You get the point } function actionBarBtnOne() { Eval( hotbar1button1.command ); } //Etc...