Menu music does not play when reentering the menu.
by Jedive · in Torque Game Engine · 06/12/2005 (7:39 am) · 4 replies
I am making a game prototype using tutorial.base as the startign point. I have added some background music to the menu.
To do it, on the "audioProfiles.cs" file, I have added a new AudioProfile datablock, defined as follows:
"AudioLoopingGui" is an AudioDescription defined in the same file (standard stuff that came with tutorial.base). When the game starts, it works perfectly. When I click the "Start!" button, the mission is loaded and the game starts. After that, when I exit the mission and come back to the menu, the music is not played, and I receive the following console message:
I decided to move the datablock from audioProfiles.cs to the MainMenuGui::onWake() function, right before alxPlay() is called, to ensure that the AudioProfile is defined, as the datablock will be redefined each time we reenter the menu. I receive the following error then:
Which means that the AudioDescription created befored cannot be found. So... I guess that after you exit form a mission, all the datablocks are deleted, including the ones used in the menu? That makes sense, as the file audioProfiles.cs, which defines all the datablocks for the audio, is loaded on the iniClient() function, just on the game startup, and not every time we enter the menu, so if the MissionCleanup deletes the datablocks, they are not loaded again...
So my question is... to fix that, is it ok to just move the line 'exec("./scripts/audioProfiles.cs");' from the function initClient() to MainMenuGui::onAdd()? This way, they will be redefined everytime the player enters the menu. I am asking because I don't know if this is an optimal way to do it (maybe it is a waste of memory, as they are redefined a lot of times?), or if there are better ways.
Thanks.
To do it, on the "audioProfiles.cs" file, I have added a new AudioProfile datablock, defined as follows:
datablock AudioProfile(MenuAudio)
{
filename = "~/data/sound/music/theawakening.ogg";
description = AudioLoopingGui;
preload = true;
};"AudioLoopingGui" is an AudioDescription defined in the same file (standard stuff that came with tutorial.base). When the game starts, it works perfectly. When I click the "Start!" button, the mission is loaded and the game starts. After that, when I exit the mission and come back to the menu, the music is not played, and I receive the following console message:
Quote:Unable to locate audio profile 'MenuAudio'
I decided to move the datablock from audioProfiles.cs to the MainMenuGui::onWake() function, right before alxPlay() is called, to ensure that the AudioProfile is defined, as the datablock will be redefined each time we reenter the menu. I receive the following error then:
Quote:Object 'AudioLoopingGui' is not a member of the 'AudioDescription' data block class
Which means that the AudioDescription created befored cannot be found. So... I guess that after you exit form a mission, all the datablocks are deleted, including the ones used in the menu? That makes sense, as the file audioProfiles.cs, which defines all the datablocks for the audio, is loaded on the iniClient() function, just on the game startup, and not every time we enter the menu, so if the MissionCleanup deletes the datablocks, they are not loaded again...
So my question is... to fix that, is it ok to just move the line 'exec("./scripts/audioProfiles.cs");' from the function initClient() to MainMenuGui::onAdd()? This way, they will be redefined everytime the player enters the menu. I am asking because I don't know if this is an optimal way to do it (maybe it is a waste of memory, as they are redefined a lot of times?), or if there are better ways.
Thanks.
#2
06/12/2005 (9:22 am)
Ok I've found where the error is. I defined all AudioProfiles and AudioDescriptions as "datablock AudioProfile(x)" or "datablock AudioDescription(x)". If I declare them as "new AudioProfile(x)" and "new AudioDescription(x)", they work perfectly without having to reaload the script each time I enter the menu... so this makes me think... when should I define a new datablock using the "datablock" keyword, and when using the "new" keyword?
#3
07/10/2005 (9:14 pm)
@Jedive - "new" is used on all client side scripts located under the tutorial.base/client directory. "datablock" is use on all server side scripts located under the tutorial.base/server directory.
#4
07/11/2005 (11:43 am)
Thanks BigPapa, this clears it up a lot :D
Torque Owner Stefan Lundmark
Have you made any changes to game.cs?
You should not have to move the AudioDescription to OnWake or OnAdd, but it sure won't hurt your game. The memory footprint won't grow (at least not when I tried) if you redefine it.
I cannot get the problem to produce on TGE 1.3 though, so I believe there's something wrong on your end. Not saying it doesn't happen (it happened to me as well), but most likely there's some error where you execute your scriptfiles.
Good luck.
Edit: Spelling.