Levels as menus, crash and burn
by Backman · in Torque Game Builder · 08/10/2008 (9:24 am) · 2 replies
I'm having a bit of a problem with the way I do my UI. Basicly
what I'm trying to do is use levels created in TGB as my UI screens,
as opposed to using TGB's GUI system.
My problem is that by doing it this way TGB just drops out of the
game at random points. Also I'm having to put in activateDirectInput();
although it's already been started in game.cs. If I take it out it'll
crash/jump out of my game every time.
My button is a normal imagemap with the name startMainGame and class
menuButton. Different buttons have different names and thus get
assigned a different command when a level (ie a menu in this case, as
my menus are loaded as levels) is loaded.
If it's a bad idea to do menus this way it'd be great to hear why.. I'm
still learning. :) Sounds like it's a bit silly but even so, the random
crashes happen when I start my game so even if I change my menus to
all code I still need to load the first level.
Here's the code for the button that'll start the main game:
function menuButton::onLevelLoaded(%this)
{
%this.setUseMouseEvents( true );
%name = %this.getName();
if(%name $= "startMainGame")
{
%this.command = "startMainGame();";
}
}
function menuButton::onMouseUp(%this, %modifier, %worldPosition, %mouseClicks)
{
if (%this.command !$= "")
{
eval(%this.command);
}
}
function startMainGame()
{
//Canvas.setContent(mainScreenGui);
//Canvas.setCursor(DefaultCursor);
$enableDirectInput = true;
activateDirectInput();
//enableJoystick();
//sceneWindow2D.setUseObjectMouseEvents( true );
sceneWindow2D.loadLevel(expandFilename("game/data/levels/p1_level01.t2d"));
initMainGame();
}
Thanks for any help!
what I'm trying to do is use levels created in TGB as my UI screens,
as opposed to using TGB's GUI system.
My problem is that by doing it this way TGB just drops out of the
game at random points. Also I'm having to put in activateDirectInput();
although it's already been started in game.cs. If I take it out it'll
crash/jump out of my game every time.
My button is a normal imagemap with the name startMainGame and class
menuButton. Different buttons have different names and thus get
assigned a different command when a level (ie a menu in this case, as
my menus are loaded as levels) is loaded.
If it's a bad idea to do menus this way it'd be great to hear why.. I'm
still learning. :) Sounds like it's a bit silly but even so, the random
crashes happen when I start my game so even if I change my menus to
all code I still need to load the first level.
Here's the code for the button that'll start the main game:
function menuButton::onLevelLoaded(%this)
{
%this.setUseMouseEvents( true );
%name = %this.getName();
if(%name $= "startMainGame")
{
%this.command = "startMainGame();";
}
}
function menuButton::onMouseUp(%this, %modifier, %worldPosition, %mouseClicks)
{
if (%this.command !$= "")
{
eval(%this.command);
}
}
function startMainGame()
{
//Canvas.setContent(mainScreenGui);
//Canvas.setCursor(DefaultCursor);
$enableDirectInput = true;
activateDirectInput();
//enableJoystick();
//sceneWindow2D.setUseObjectMouseEvents( true );
sceneWindow2D.loadLevel(expandFilename("game/data/levels/p1_level01.t2d"));
initMainGame();
}
Thanks for any help!
#2
Cheers!
[edit]
Tried that, works just fine so thanks a bunch. I tried sticking %this.command into $command before running that command, but didn't work. Not sure why as it wouldn't be related to the object anymore?
Thanks again.
08/12/2008 (12:10 am)
Thanks, will try that! I just saw another post regarding this, don't know how I missed that one..Cheers!
[edit]
Tried that, works just fine so thanks a bunch. I tried sticking %this.command into $command before running that command, but didn't work. Not sure why as it wouldn't be related to the object anymore?
Thanks again.
Associate James Ford
Sickhead Games
%this.command = "schedule( 1, /"startMainGame();/" );";