Binding a key to a GUI
by Infinitum3D · in Torque Game Engine · 12/21/2006 (10:13 am) · 3 replies
I'm trying to add a "Display Map" feature using the M key to toggle the map of the world on/off. This isn't going to draw a map or modify the map or anything like that. It will simply toggle a picture of the WorldMap.png on/off .
I'm having trouble with the moveMap.bindCmd(keyboard, "m", "toggleWorldmap();", "");
In \client\scripts\default.bind.cs and at the bottom I added this code:
//------------------
//--Map Toggle
//------------------
$worldmapState = false;
function toggleWorldmap() {
if ($worldmapState == false) {
commandToServer('DisplayWorldmapGui');
$worldmapState = true;
} else {
Canvas.setContent( PlayGui );
$worldmapState = false;
}
}
moveMap.bindCmd(keyboard, "m", "toggleWorldmap();", "");
//-----
In client\init.cs I added this to the SHELL GUI exec section:
exec("./ui/WorldMapGui.gui");
and under //Client scripts
exec("./scripts/WorldMap.cs");
In config.sys:
moveMap.bindCmd(keyboard, "m", "toggleWorldmap();", "");
And I created a WorldmapGui.cs file:
//-------------------------------------------------
// WorldMapGui.cs
//-------------------------------------------------
new ActionMap(worldMap);
worldMap.bindCmd(keyboard, "m", "toggleWorldMap();", "");
function WorldMapGui::onWake()
{
Canvas.setContent( WorldMapGui );
}
function InventoryGui::onSleep()
{
Canvas.setContent(PlayGui );
}
I also have a new GUI called WorldMapGui, with the bitmap set as my worldmap.png.
I think my problem is the moveMap.bindCmd(keyboard, "m", "toggleWorldmap();", "");
Can anyone tell me what I'm doing wrong?
Thanks!
Tony
I'm having trouble with the moveMap.bindCmd(keyboard, "m", "toggleWorldmap();", "");
In \client\scripts\default.bind.cs and at the bottom I added this code:
//------------------
//--Map Toggle
//------------------
$worldmapState = false;
function toggleWorldmap() {
if ($worldmapState == false) {
commandToServer('DisplayWorldmapGui');
$worldmapState = true;
} else {
Canvas.setContent( PlayGui );
$worldmapState = false;
}
}
moveMap.bindCmd(keyboard, "m", "toggleWorldmap();", "");
//-----
In client\init.cs I added this to the SHELL GUI exec section:
exec("./ui/WorldMapGui.gui");
and under //Client scripts
exec("./scripts/WorldMap.cs");
In config.sys:
moveMap.bindCmd(keyboard, "m", "toggleWorldmap();", "");
And I created a WorldmapGui.cs file:
//-------------------------------------------------
// WorldMapGui.cs
//-------------------------------------------------
new ActionMap(worldMap);
worldMap.bindCmd(keyboard, "m", "toggleWorldMap();", "");
function WorldMapGui::onWake()
{
Canvas.setContent( WorldMapGui );
}
function InventoryGui::onSleep()
{
Canvas.setContent(PlayGui );
}
I also have a new GUI called WorldMapGui, with the bitmap set as my worldmap.png.
I think my problem is the moveMap.bindCmd(keyboard, "m", "toggleWorldmap();", "");
Can anyone tell me what I'm doing wrong?
Thanks!
Tony
#2
12/21/2006 (11:37 am)
Quote:Try thisThat will cause it to do it twice, since it passes both key down and key up to the function. You'll need to add a variable to the function to check for that.
moveMap.bind( keyboard, m, toggleWorldmap);
Torque Owner Fucifer
moveMap.bind( keyboard, m, toggleWorldmap);