Game Development Community

GUI Tutorial 1

by Kamar Bratko · in Torque Game Builder · 07/10/2007 (3:16 pm) · 7 replies

Hi,

They call me Ishmael...I mean noob.

Very new to TGB and am starting up with the GUI tutorials. As a base I'm using "ExampleMyFishGame".

I'm trying to follow this tutorial: http://tdn.garagegames.com/wiki/TGB/MiniTutorials/Your_First_GUI_Tutorial

I believe that I followed everything step for step. Things I've verified.

1) I have a a static Sprite a "Fish"
2) I updated the main.cs and the game.cs as follows:

MAIN.CS
{
// Load up the in game gui.
exec("~/gui/mainScreen.gui");

// I Added this. *****************************************************
exec("~/gui/guiNewGui.gui");

exec("./gameScripts/game.cs");

if ($runWithEditors)
{
toggleLevelEditor();
return;
}

startGame($levelEditor::LastLevel[$currentProject]);
}

//---------------------------------------------------------------------------------------------
// shutdownProject
// Clean up your game objects here.
//---------------------------------------------------------------------------------------------
function shutdownProject()
{
endGame();
}

function setupKeybinds()
{
new ActionMap(moveMap);
//moveMap.bind("keyboard", "a", "doAction", "Action Description");
}

GAME.CS

function startGame(%level)
{
exec("./player.cs");
exec("./fishfood.cs");
exec("./fish.cs");
exec("./mine.cs");


// Set The GUI.
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);

moveMap.push();
if( isFile( %level ) || isFile( %level @ ".dso"))
sceneWindow2D.loadLevel(%level);

// I Added this. *****************************************************
sceneWindow2D.setUseObjectMouseEvents(true);
}

//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
}

// I Added this. *****************************************************
function Menu::onMouseDown(%this)
{
Canvas.pushDialog(guiNewGui);
}

3) I've created a GUI and saved it as guiNewGui.gui in the /Gui folder. its a guiButtonCtrl.

When I run the game and click on my fish/gui trigger nothing happens.
What painfully thing am I missing?

Thanks.

About the author

Director of Project Management for a Digital Forensics and Management company called BIA. www.biaprotect.com Gamer at heart.


#1
07/10/2007 (4:01 pm)
Does your fish belong to the the Menu class?
#2
07/10/2007 (4:07 pm)
It does, with 'Use Mouse Events" checked as well.

Nothing else in that area is marked or filled out.
#3
07/10/2007 (4:12 pm)
Hmm did you try putting an error("onMouseDown"); or something in your onMouseDown() function? Also, perhaps it is because the onMouseDown callback has other parameters...try...
function Menu::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)
{
Canvas.pushDialog(guiNewGui);
}
#4
07/10/2007 (4:18 pm)
I commented out the prevous and added yours but to no avail.

I can't help thinking I'm missing something basic.

// Added GUI line
//function Menu::onMouseDown(%this)
//{
// Canvas.pushDialog(guiNewGui);
//}

function Menu::onMouseDown(%this, %modifier, %worldPosition, %mouseClicks)

{

Canvas.pushDialog(guiNewGui);

}
#5
07/10/2007 (4:20 pm)
Add error("mousedown"); to that function and then open the console by hitting the ~ key when you run the game. Any errors or warnings?
#6
07/10/2007 (7:26 pm)
I couldn't find the error log and ironically you can't cut and paste directly from the console.

So here's the like that is probably the error;

Error: cannot unlink namespace parent linkage for Menu for GuiButtonCtrl.
Error: cannot change namespace parent linkage for Menu form GuiButtonCtrl to t2dStaticSprite.

(I took a screen shot and retypoed)

btw thx
#7
07/11/2007 (8:22 am)
Do you have a GuiButtonCtrl whose name is (or ever was) Menu? That's probably what is confusing it. In older versions of TGB, I would get error this even after renaming. You could try giving the fish and onMouseDown function a different class altogether and see if that works...?