Game Development Community

Timer & Calling a GUI on level completion

by Maarten Visser · in Torque Game Builder · 04/09/2008 (12:14 pm) · 6 replies

Hi there all, I've got 2 questions for TGB..

So, I'm trying to create a brick/arkanoid-like game.. (You have to destroy all bricks in the field by bouncing a ball to them)

So basically I want to do 2 things now, but I'm having a bit of a difficulty with the scripting:

- I want to create a timer, which displays how long your game is taking already
- I want to let a Gui show up when all the bricks are gone. (Like "Congrats, you made it! Move on to the next level")

Problem 1, the Timer)
I have got a timer gui already, it says: "TIME:", followed by "0"

if(!isObject(GuiTextW22Profile)) new GuiControlProfile (GuiTextW22Profile : GuiTextProfile)
	{
	   fontSize = 22;
	   fontColor = "220 220 220";
	   fontType = "JuneBug";
	};
	new GuiControl(ScoreboardGui) {
	   canSaveDynamicFields = "0";
	   Profile = "GuiModelessDialogProfile";
	   HorizSizing = "right";
	   VertSizing = "bottom";
	   border=0;
	   Position = "0 0";
	   Extent = "200 40";
	   MinExtent = "8 2";
	   canSave = "1";
	   Visible = "1";
	   hovertime = "1000";
	   modal="false";
	      new GuiTextCtrl() {
	         canSaveDynamicFields = "0";
	         Profile = "GuiTextW22Profile";
	         HorizSizing = "right";
	         VertSizing = "bottom";
	         Position = "415 10";
	         Extent = "96 20";
	         MinExtent = "8 2";
	         canSave = "1";
	         Visible = "1";
	         hovertime = "1000";
	         text = "TIME:";
	         maxLength = "1024";
	      };
	      new GuiTextCtrl(ScoreboardGuiScore) {
	         canSaveDynamicFields = "0";
	         Profile = "GuiTextW22Profile";
	         HorizSizing = "right";
	         VertSizing = "bottom";
	         Position = "511 10";
	         Extent = "520 20";
	         MinExtent = "8 2";
	         canSave = "1";
	         Visible = "1";
	         hovertime = "1000";
	         text = "0";
	         maxLength = "1024";
	      };

	};

That's the GUI code for the timer..

then I have a .cs file, which is supposed to update this ScoreboardGuiScore...

function playerRed::onUpdateScene(%this) {

   %timeLeft = %this.getSceneTime();
   
   ScoreboardGuiScore.setValue(%timeLeft);
}

In which playerRed is my player, which moves around the level...

What am I doing wrong for this timer thing?

Problem 2, the GUI at completion)
So, I have like .. 20 bricks..

Condition: All bricks are gone (should I add all bricks to a class, and make a script on it?)
Action: Canvas.pushdialog(level1end);

That is kind off what I want, how can I do it?

Thanks for your time, and your help, in advance :)
-MaarX

#1
04/09/2008 (12:19 pm)
For the GUI at completion, I would add all the brinks to a simGroup on level load, and each time a brick is destroyed, remove it from the group, and check if there are any left. If not, then end the level, and load up the new GUI...

As for the timer, I didn't look that close, but is it setText instead of setValue? I don't remember for sure, but you might give it a try...
#2
04/09/2008 (12:22 pm)
How can I add all the bricks to a simgroup? How is it done.. I'm kind off a noob with TGB atm.. no really scripting experience etc..

EDIT:
I have added my bricks to a simgroup (I think) using this piece of code:

function brick::onAdd(%this)
{
   if(!isObject(brickSet))
      new SimSet(brickSet);

   brickSet.add(%this);

   //Test it out
   brickSet.listObjects();
}

All the scripting names for all the bricks are 'brick' for this.. When I open the console and enter: brickSet.listObjects(); I get a list off all my bricks.

But, one big problem: Whenever my ball touches a brick, that brick being touched is not being removed/hit, but instead another one (example: another one which is out of range for the ball)

So, with this simset, all the bricks are acting like a group, but I still want them to be individual, and to be removed once hit...

Any suggestions/solutions?

For the timer:
I have tried setText insdead of setValue.. It isn't working:(
#3
04/12/2008 (2:42 am)
Update on the Timer..

The GuiTextCtrl is working, when I enter this in my console, the timer gets updated:

GuiTime.setText( Hello );

However, I need the scene's time to be displayed there..
Torque does not recognize this function: getSceneTime(); (I get a reply: Unable to find function getSceneTime)

However, small update:

When I type in my console the following: GuiTime.setValue( playerRed.getLifeTime());

Then the GuiTime text gets updated and says 0.

But, it seems like there is no track of time in my game? How can I make these timers start?
#4
04/21/2008 (3:38 am)
Is there anyone that has dealt with this before?

How to get the scenetime?
#5
04/21/2008 (9:08 am)
GetSimTime()
#6
04/25/2008 (4:36 pm)
Thanks,, for the command, but I'm still not getting anywhere..

What's wrong with this code:
function updateTime(%this)
{
   GuiTime.setValue(GuiTime.getValue() + 1);
%this.timerSchedule = %this.schedule(1000, updateTime);
}

function t2dSceneWindow::onUpdateScene(%this)
{
   GuiTime.setvalue(getSimTime());
%this.timerSchedule = %this.schedule(1000, onUpdateScene);
}

They're 2 different functions, both trying to update my timer.. They both don't work.

When I enter GuiTime.setValue(GuiTime.getValue() + 1); into my console, the timer sets itself as 1, another press and it's 2.. So console entering works..

Is my function not being called (and how to call it then)? (the script is loaded)