Game Development Community

How do I call .gui files to only load in certain levels?

by Path · in Torque Game Builder · 02/27/2009 (6:36 pm) · 5 replies

I have a .gui that contains an .ogm cut scene that I need to know how to put in the main.cs code:


exec("~/gui/Level2cutscene.gui")



and


exec("~/gui/Level4cutscene.gui")



to load only when Level2 & Level4 are loaded?

I've tried with little luck the following script attempt in the main.cs:

function initializeProject()
{

exec("~/gui/mainScreen.gui");
exec("./gameScripts/game.cs");

function Level2::onLevelLoaded(Level2, %scenegraph)
{
exec("~/gui/Level2cutscene.gui")
}

function Level4::onLevelLoaded(Level4, %scenegraph)
{
exec("~/gui/Level4cutscene.gui")
}
}


Is their a better way like a standard gamescript.cs to accomplish this?

#1
02/27/2009 (8:18 pm)
Leave it in init.cs or game.cs (wherever you normally exec it). exec() doesn't run the GUI, it just compiles it and gets it ready for all of its functions and GUIs to be called.

What you want to do is call the GUI in the onLevelLoaded(). Calling the exec just compiles it, really. Hope that helps.
#2
02/28/2009 (2:39 pm)
Ok, I should've remembered the part about .exec()'s only setting up and not actually running. Thanks for the reminder.

So I went back and modified the call script for GuiTheoraCtrl from TDN:

openingLogo.setFile("./game/data/images/TEST3.ogm");

and added it to the behavior. Despite having the
exec("~/gui/StartUp.gui");
in game.cs I had to also add it right above the .gui call in the onLevelLoaded behavior to get it to run at normal speed(without it, it ran slower than molasses and without audio).

I do have three new issues I need to resolve:

1) I have audio but no video. Video/Audio all worked fine when played directly from the main.cs Canvas.setContent( StartUp.gui);

I get the following script log(normal black type/not an error):
TheoraTexture - Loading file './game/data/images/TEST3.ogm'
  Ogg logical stream 0 is Theora 304x304 29.97 fps video
       - Frame content is 304x304 with offset (0,0).
  Ogg logical stream 1 is Vorbis 2 channel 44100 Hz audio.

Inside the StartUp.gui, the video part has Visible = "1";

2) How and where do I put the script to make it jump to the next level once the .ogm video is done playing?

3) How and where do I put the script to have a "clickthrough" to bypass the cut scene?

Thanks in advance!
#3
02/28/2009 (2:47 pm)
1) Well, I can't help too much with Theora in specific, as I haven't worked with those features. Hopefully someone else can help you with that.

2) All the scripts should be exec'ed in the same place.

3) Just create a function for that control that uses the onClick() callback to exit out. If it doesn't have a mouse callback, you can use the GuiMouseEventCtrl (pretty sure that's what it's called, don't have my docs with me ATM) to capture the event.

Remember, just because it's a .gui file doesn't mean that you can't have functions in it below the GUI area. You can also have multiple GUI's defined in one .gui file (I have one with five HUD's defined, and functions for them below their definitions).
#4
02/28/2009 (2:49 pm)
Thanks for the suggestions!
#5
03/07/2009 (11:24 am)
For those trying to figure out this problem, this post helped fill in a lot of blanks:

http://www.garagegames.com/community/forums/viewthread/48713

My only issue now is trying to figure out how to add functions to this .gui so I can control the click through & load next level command.

I pulled the functions from the GuiAviBitmapCtrl code, but can't seem to integrate them into theora even though they both have very similar structures.