Can't make audio work from scripts - Resolved
by Stevebro · in Torque Game Builder · 03/15/2010 (1:13 pm) · 11 replies
Hi can anyone help me solve this problem it's really driving me crazy I've been stuck for days.
When I define my audio datablocks in script file they will not play. I don't get any errors just no sound.
new AudioDescription(AudioLooping){
volume = 1.0;
isLooping = true;
is3D = false;
type = $GuiAudioType;
};
new AudioProfile(backgroundAudio){
filename = "./game/data/audio/loop2.wav";
description = "AudioLooping";
preload = true;
};
I call the script in my main.cs located in my game folder.
exec(./gamescripts/audiodatablocks.cs);
If I enter $sound = alxPlay(backgroundAudio); into the console nothing happens I don't get an error or sound. If I do echo($sound) in the console window it returns 0.
However if I enter these same datablocks in the console window of a running project and then enter $sound = alxPlay(backgroundAudio); the sound plays perfectly fine.
I've tried this with TGB 1.7.4 on both windowsXP and OSX 10.6.2 with the same results.
Any insight anyone can provide is greatly appreciate, my project has come to a grinding halt.
When I define my audio datablocks in script file they will not play. I don't get any errors just no sound.
new AudioDescription(AudioLooping){
volume = 1.0;
isLooping = true;
is3D = false;
type = $GuiAudioType;
};
new AudioProfile(backgroundAudio){
filename = "./game/data/audio/loop2.wav";
description = "AudioLooping";
preload = true;
};
I call the script in my main.cs located in my game folder.
exec(./gamescripts/audiodatablocks.cs);
If I enter $sound = alxPlay(backgroundAudio); into the console nothing happens I don't get an error or sound. If I do echo($sound) in the console window it returns 0.
However if I enter these same datablocks in the console window of a running project and then enter $sound = alxPlay(backgroundAudio); the sound plays perfectly fine.
I've tried this with TGB 1.7.4 on both windowsXP and OSX 10.6.2 with the same results.
Any insight anyone can provide is greatly appreciate, my project has come to a grinding halt.
#2
The path did the trick "~/data/audio/loop2.wav" instead of "./game/data/audio/loop2.wav" oddly the exact opposite is true if you are entering script through the console.
03/16/2010 (10:07 am)
Thanks Dean.The path did the trick "~/data/audio/loop2.wav" instead of "./game/data/audio/loop2.wav" oddly the exact opposite is true if you are entering script through the console.
#4
07/20/2010 (8:55 pm)
Alan, do the file names of your audio files start with a number by chance?
#5
07/21/2010 (8:25 pm)
No. I am following the audio tutorial. There is no sound at all. Very frustrating to say the least. I am doing everything that has been suggested. I don't get it.
#6
I've never done the audio tutorial, so I really don't know what it entails but most of the tutorials are out of date.
07/21/2010 (8:27 pm)
Post the code you're using for audio and I can try to help out. It's pure speculation as to what could be wrong without that.I've never done the audio tutorial, so I really don't know what it entails but most of the tutorials are out of date.
#7
new AudioDescription(AudioNonLooping)
{
volume = 1.0;
isLooping= false;
is3D = false;
type = $GuiAudioType;
};
new AudioDescription(AudioLooping)
{
volume = 1.0;
isLooping= true;
is3D = false;
type = $GuiAudioType;
};
// --------------------------------------------------------------------
// Background Loop.
// --------------------------------------------------------------------
new AudioProfile(backgroundAudio)
{
fileName = "~/game/data/audio/BLIP.wav";
description = "AudioLooping";
preload = true;
};
// --------------------------------------------------------------------
// Single Blip.
// --------------------------------------------------------------------
new AudioProfile(blipAudio)
{
fileName = "~/game/data/audio/BLIP.wav";
description = "AudioNonLooping";
preload = true;
};
And here is my game.cs code:
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// startGame
// All game logic should be set up here. This will be called by the level builder when you
// select "Run Game" or by the startup process of your game to load the first level.
//---------------------------------------------------------------------------------------------
function startGame(%level)
{
exec("~/gameScripts/audioBlock.cs");
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
new ActionMap(moveMap);
moveMap.push();
$enableDirectInput = true;
activateDirectInput();
enableJoystick();
sceneWindow2D.loadLevel(%level);
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
moveMap.delete();
}
no sound when I input alxPlay(blipAudio); in the console.
07/21/2010 (9:58 pm)
Here is the audioBlock.cs code:new AudioDescription(AudioNonLooping)
{
volume = 1.0;
isLooping= false;
is3D = false;
type = $GuiAudioType;
};
new AudioDescription(AudioLooping)
{
volume = 1.0;
isLooping= true;
is3D = false;
type = $GuiAudioType;
};
// --------------------------------------------------------------------
// Background Loop.
// --------------------------------------------------------------------
new AudioProfile(backgroundAudio)
{
fileName = "~/game/data/audio/BLIP.wav";
description = "AudioLooping";
preload = true;
};
// --------------------------------------------------------------------
// Single Blip.
// --------------------------------------------------------------------
new AudioProfile(blipAudio)
{
fileName = "~/game/data/audio/BLIP.wav";
description = "AudioNonLooping";
preload = true;
};
And here is my game.cs code:
//---------------------------------------------------------------------------------------------
// Torque Game Builder
// Copyright (C) GarageGames.com, Inc.
//---------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
// startGame
// All game logic should be set up here. This will be called by the level builder when you
// select "Run Game" or by the startup process of your game to load the first level.
//---------------------------------------------------------------------------------------------
function startGame(%level)
{
exec("~/gameScripts/audioBlock.cs");
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
new ActionMap(moveMap);
moveMap.push();
$enableDirectInput = true;
activateDirectInput();
enableJoystick();
sceneWindow2D.loadLevel(%level);
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
moveMap.delete();
}
no sound when I input alxPlay(blipAudio); in the console.
#8
07/21/2010 (10:15 pm)
I made the change to the path in the audio profiles as Dean indicated and it worked perfectly:new AudioDescription(AudioNonLooping)
{
volume = 1.0;
isLooping= false;
is3D = false;
type = $GuiAudioType;
};
new AudioDescription(AudioLooping)
{
volume = 1.0;
isLooping= true;
is3D = false;
type = $GuiAudioType;
};
// --------------------------------------------------------------------
// Background Loop.
// --------------------------------------------------------------------
new AudioProfile(backgroundAudio)
{
fileName = "~/data/audio/Blip.wav";
description = "AudioLooping";
preload = true;
};
// --------------------------------------------------------------------
// Single Blip.
// --------------------------------------------------------------------
new AudioProfile(blipAudio)
{
fileName = "~/data/audio/Blip.wav";
description = "AudioNonLooping";
preload = true;
};
#9
A quick question. What tool do you use for editing the script files? Notepad sucks.
07/21/2010 (10:48 pm)
OK, got it. Weird. Thanks for your help. A quick question. What tool do you use for editing the script files? Notepad sucks.
#10
I use Torsion. I wouldn't use TGB without it.
If you just want an editor I recommend Notepad++. If you're on a Mac, I'm not really sure but I hear jEdit is good and supposedly there's a TorqueScript highlighter called tIDE.
07/21/2010 (11:11 pm)
No problem. Paths are a bit of a pain.I use Torsion. I wouldn't use TGB without it.
If you just want an editor I recommend Notepad++. If you're on a Mac, I'm not really sure but I hear jEdit is good and supposedly there's a TorqueScript highlighter called tIDE.
#11
09/16/2011 (4:09 am)
Thanks to this thread I was able to complete the audio tutorial. Hurray!
Torque 3D Owner Dean Parker
Serendip Games
I am not sure why it is not working, but this is what I use.
new AudioDescription(AudioNonLooping) { volume = 1.0; isLooping = false; id3D = false; type = $GuiAudioType; }; new AudioDescription(AudioLooping) { volume = 1.0; isLooping = true; id3D = false; type = $GuiAudioType; }; new AudioProfile(menuAudio) { fileName="~/data/audio/menu.wav"; description = "AudioLooping"; preload = true; }; new AudioProfile(planeAudio) { fileName="~/data/audio/plane.wav"; description = "AudioLooping"; preload = true; };I compile in the main.cs file below the game.cs part.
// Exec game scripts. exec("./scripts/game.cs"); exec("./scripts/audioFX.cs");To call the sounds I use...