GlobalActionMap.bind called twice
by Novack · in Torque Game Engine · 09/30/2007 (7:34 pm) · 5 replies
Im trying to solve a problem of the RTS-SK. When toggleFullScreen, the miniMapHud must be rebuilded.
So Im trying to change default.bind.cs
From this:
GlobalActionMap.bindCmd(keyboard, "alt enter", "", "toggleFullScreen();");
To this:
The problem is that reDrawMiniMapOnToggleScreen() is beeing called TWICE each time I hit alt+enter. As a result I cannot change the screen mode.
I know GlobalActionMap.bindCmd allow a second parameter (kind of onKeyDown and oKeyUp), but GlobalActionMap.bind though is acepting the second parameter ("") makes no effect, and still make the call twice.
Anyone knows how I can workaround this?
So Im trying to change default.bind.cs
From this:
GlobalActionMap.bindCmd(keyboard, "alt enter", "", "toggleFullScreen();");
To this:
function reDrawMiniMapOnToggleScreen()
{
toggleFullScreen();
// Schedule(10, rebuildMap, true);
}
GlobalActionMap.bind(keyboard, "alt enter", reDrawMiniMapOnToggleScreen);The problem is that reDrawMiniMapOnToggleScreen() is beeing called TWICE each time I hit alt+enter. As a result I cannot change the screen mode.
I know GlobalActionMap.bindCmd allow a second parameter (kind of onKeyDown and oKeyUp), but GlobalActionMap.bind though is acepting the second parameter ("") makes no effect, and still make the call twice.
Anyone knows how I can workaround this?
About the author
http://cyberiansoftware.com.ar/
#2
10/01/2007 (10:47 am)
Brian it works perfectly (I didnt know about %keystate). Thank you very much!
#3
.bindCmd gives you additional flexibility and lets you call two different functions--one on key press, and one on key release, while .bind only allows you to call one function, but it is called twice (as you noted)--once with a value of 1 as a parameter (normally called %val, called %keyState in Brian's example) during the "make" event (key pressed), and a value of 0 during the "break" event (when the key is released.
Since the original command you are changing has a null function for the make event, and the same function you are using in your revised version for the break event, the only effective difference between the original version and the one you re-wrote is that the redraw will be done when alt enter is released, instead of when it is pressed.
10/01/2007 (6:34 pm)
Just for reference, the original .bindCmd does exactly what your revised version does--call the function once during the make/break combination of a key press and release..bindCmd gives you additional flexibility and lets you call two different functions--one on key press, and one on key release, while .bind only allows you to call one function, but it is called twice (as you noted)--once with a value of 1 as a parameter (normally called %val, called %keyState in Brian's example) during the "make" event (key pressed), and a value of 0 during the "break" event (when the key is released.
Since the original command you are changing has a null function for the make event, and the same function you are using in your revised version for the break event, the only effective difference between the original version and the one you re-wrote is that the redraw will be done when alt enter is released, instead of when it is pressed.
#4
In fact, thanks to your comment I catch my original problem: due to a mistyping problem, I believed that .bindCmd only work with engine calls but no script functions (Thats why I finally remained with .bind)
10/01/2007 (6:58 pm)
Thanks for that Stephen. The conceptual threads behind the things are always welcome.In fact, thanks to your comment I catch my original problem: due to a mistyping problem, I believed that .bindCmd only work with engine calls but no script functions (Thats why I finally remained with .bind)
#5
It is possible with a bit of scripting trickery to have .bind/.bindCmd actually call namespace methods, but it's not common practice in TGE. It's used occasionally in TGB as a shortcut, but not nearly as often in TGE/TGE-A.
10/01/2007 (7:04 pm)
No problem at all--glad we both got some theory out, and brought out a misconception--by nature, both .bind and .bindCmd are designed to be tied to script functions (global scope), not necessarily Console Functions--in fact, I've not ever seen them call Console Functions, although it should work fine in that mode as well.It is possible with a bit of scripting trickery to have .bind/.bindCmd actually call namespace methods, but it's not common practice in TGE. It's used occasionally in TGB as a shortcut, but not nearly as often in TGE/TGE-A.
Torque Owner Michael Bacon
Default Studio Name
I believe this should work for you.
function reDrawMiniMapOnToggleScreen(%keyState) { if (%keyState != 0) { // key was pressed toggleFullScreen(); // Schedule(10, rebuildMap, true); } else { // key was released } } GlobalActionMap.bind(keyboard, "alt enter", reDrawMiniMapOnToggleScreen);