Game Development Community

Why Doesn't GUI Start Button Work?

by Jay Jennings · in Torque Game Builder · 09/27/2009 (6:01 pm) · 3 replies

I created a button on a GUI and in Command put this:

startGame(expandFilename($Game::DefaultScene));

When the button shows up in the game and I click it the GUI vanishes but the game doesn't start.

However, if I put this in Command:

startGameHere();

...and then put this in game/main.cs...

function startGameHere()
{
	startGame(expandFilename($Game::DefaultScene));	
}

...pressing the button works the way it should.

But the command that's happening is the same in both cases -- why does it work inside a function but not as the Command for the button?

Jay Jennings

About the author

Make my living writing and selling ecommerce tools -- but I'd rather be writing games (of course). My family of four lives in 208 square feet and we may be in YOUR town next week.


#1
09/27/2009 (8:14 pm)
What is the value of $Game::DefaultScene? You will probably find that expandFilename doesn't work well coming from the GUI (expandFilename relies on the script that a command was executed from, and since a GUI event is not executed from a script file, it won't work). Your best bet is to either ensure that $Game::DefaultScene is the full path, i.e. "game/data/levels/myLevel.t2d", or use that wrapper method.
#2
09/27/2009 (8:23 pm)
Thanks, Phillip. Since it works by calling the function I'll just keep doing that -- I'd kind of rather do that than insert "real code" into the button command, anyway.

I'm just so new at TGB that I'm trying to figure out why things work they way they do -- thanks for the info.

Jay Jennings
#3
09/28/2009 (10:46 am)
I can confirm this Jay. Identical issue that I worked around using the same solution as you, but I think it may have to do with the string needing some escape characters but I haven't done any testing on that theory.