Game Development Community

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

#1
12/21/2006 (10:57 am)
Try this

moveMap.bind( keyboard, m, toggleWorldmap);
#2
12/21/2006 (11:37 am)
Quote:Try this

moveMap.bind( keyboard, m, toggleWorldmap);
That 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.
#3
12/22/2006 (5:16 pm)
I fixed it. Check out the "Torque 101:" thread for details.

Tony