2012-02-02 19:31:51

hi everyone

as i said on the releases forum and on vp i have chosen to take another way in programming my games. but it would be quite nice to also add sapi voicing and sounds.
i am creating my games in bgt.
so i am interested how to add the sapi voice and a few sounds. and when to type the code to play the sound and the moment + code to play the sapi voice.

help will be appreciated.

ciao

mike

Visit the following website to see what games we have:
http://www.nonvisiongames.com
Or the following English marketplace to see what retrogames and game merchandise I am selling:
https://www.retro-kingdom.com

2012-02-02 19:34:27

hi
you can look through the languaga tutorials, of course
then you have programming practices, it might come in handy
and then you have references for each function in the reference section of the help topics
and last but not the least, there are some other example games that you can look upon by going to the bgt site.

He picked up the wrench and broke the guy’s wrist with it, one, and then the other wrist, two, and turned back and did the same to the guy who had held the hammer, three, four. The two men were somebody’s weapons, consciously deployed, and no soldier left an enemy’s abandoned ordnance on the field in working order.

2012-02-02 20:07:04

There is a sound object, a tts_voice object, and for more convenience there's the sound_pool object. All three are in the manual (somewhere like c:\program files\bgt\bgt.chm ). tts_voice and sound are in the reference > foundation layer > object reference, and the sound_pool is in reference > helper layer > object reference.
Then there's my custom_voice class, which I wouldn't keep advertising if I didn't find it convenient. tongue
http://dl.dropbox.com/u/16520690/custom_voice.bgt
It works very similarly to the tts_voice class, so you should learn how to use that first. The main difference is the lack of a rate property (use the set_rate method instead), and the addition of a few things (like the options_menu method for letting the user adjust things, a pitch setting, the ability to save and load configuration, etc).

But, yeah, look for sound and tts_voice in the manual.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2012-02-02 20:53:58

Hi,
To make a sound, first
sound your_sound;
Your_sound is the custom name you can change it. Also, instead of spaces, you should use underlines. Buy typing
sound your_sound;
You have declared a sound object. So lets load it:
your_sound.load("directory");
If you want to use backslashes in the directory, you should put two backslashes. To play it, there are a few methods:
play();
This method will play the sound.
play_wait();
This method will play the sound, and additionelly will wait for the sound to stop playing.
play_looped:
This will loop the sound like a background music.
Also, you can stop a sound. To use one of the playing methods, you should type:
For example, I will use the play_wait method:
test_sound.play_wait();
To stop it,
your_sound.stop();
Let's go to the tts voice.
To declare it,
tts_voice your_voice;
You can change it's name too. I usually use v.
Ok. We have now declared it. Now let's get it to speak some text:
your_voice.speak_wait("Hello, I am your tts voice. Goodbye.");
For more information, please look at the manual.

I post sounds I record to freesound. Click here to visit my freesound page
I usually post game recordings to anyaudio. Click here to visit my anyaudio page

2012-02-02 21:39:38

hi everyone

i appreciate all your help, but burak or somebody else on wich position should i place the code for sounds? i've written the code under de void main and the {
but i receive errors. and i want to use wave sounds, please can somebody give an example about the way i should write the code with a wave file?

i've to admit i had looked in the manual a time ago, but i don't understand it. my oppinion about the manual is that the manual is very vague.

ciao

mike

Visit the following website to see what games we have:
http://www.nonvisiongames.com
Or the following English marketplace to see what retrogames and game merchandise I am selling:
https://www.retro-kingdom.com

2012-02-03 04:39:50

Hi Mike,

As in all things there is a certain order or structure to programming. Generally, speaking you start by including any files needed by your project, then you declare variables and objects, add custom functions, and call main() to launch the program. Here is a very very simple example.

sound g_sound; // global sound object
voice_tts g_voice; // Global voice object

// Name: main ().
// Description: Entry point for the application.
void main ()
{

    // Load a wav file
    g_sound.Load ("Sounds/Sound.wav");

    // Play the sound
    g_sound.play ();
   
    // Speak the program name
    // and wait for it to finish
    // before exiting the script
    g_voice.speak_wait ("Sample application version 1.0");
}

If you examine this little script carefully you see I declared the sound and voice objects before creating the main function. Inside the main function I loaded and played a sound file using the sound object, and spoke a simple message with SAPI.

Notice here I specifically used a forward slash and not a backslash to load a file from a subdirectory. Get use to using forward slashes for directories as most programming languages won't allow you to use a backslash without an escape character, and Microsoft Windows is the only OS in existance that uses backslashes for directories anyway. Mac OS, Linux, FreeBSD, etc all use forward slashes when accessing files from subdirecgtories.  Windows supports this too, but Microsoft being Microsoft they adopted some off the wall standard back in the Dos days that is totally non-standard. Bottomline, ignore the advice above of using two backslashes and use a single forward slash instead. Its what most professionals do.

Thomas

Sincerely,
Thomas Ward
USA Games Interactive
http://www.usagamesinteractive.com

2012-02-03 11:05:09

hi thomas and others

@thomas

regarding to your example. it makes the things more clear than ever, but i'll paste the testscript i've written for everyone who wants to read it.

voice_tts g_voice;
void main()
{
g_voice.speak_wait(

Visit the following website to see what games we have:
http://www.nonvisiongames.com
Or the following English marketplace to see what retrogames and game merchandise I am selling:
https://www.retro-kingdom.com

2012-02-03 11:17:15

If the actual script ends there, it's not going to work just because both a function and method invocation are opened without being closed.

If the rest is something to the effect of


"Hello world.");
}


Then it should work just fine.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2012-02-03 11:21:20

hi everyone

sorry for double posting but i've looked up the post from burak again and i've typed the tts_voice v; code and typed v.speak_wait("my text"); code and it works!

when i come home i'll make the millionaire quiz fully spoken.

thank you very, very much you all.

ciao

mike

Visit the following website to see what games we have:
http://www.nonvisiongames.com
Or the following English marketplace to see what retrogames and game merchandise I am selling:
https://www.retro-kingdom.com

2012-02-03 11:34:48

You're welcome.

I post sounds I record to freesound. Click here to visit my freesound page
I usually post game recordings to anyaudio. Click here to visit my anyaudio page

2012-02-03 12:15:55

hi

@cae

i didn't thought there was a reply so fast after my paste of the code ...

but cae, the code didn't end there, i believe the copy command didn't did it's work as i wanted.

ciao

mike

Visit the following website to see what games we have:
http://www.nonvisiongames.com
Or the following English marketplace to see what retrogames and game merchandise I am selling:
https://www.retro-kingdom.com

2012-02-03 17:01:43

Glad to help. Just a note about your script. In addition to it not closing the function I also noticed a missing quote before the start of your message to speak. You need to remember to surround strings with quotes or the script compiler will think they are functions or variables and bomb out.

Sincerely,
Thomas Ward
USA Games Interactive
http://www.usagamesinteractive.com

2012-02-03 17:53:56

hi tward
you said that single forward slashes should be used in bgt paths,
but in the manual, and at some hopeful other places, its mentioned to use double back slashes there.

so, what do you think, the tutorials are wrong? or you

He picked up the wrench and broke the guy’s wrist with it, one, and then the other wrist, two, and turned back and did the same to the guy who had held the hammer, three, four. The two men were somebody’s weapons, consciously deployed, and no soldier left an enemy’s abandoned ordnance on the field in working order.

2012-02-03 19:02:32

The manual says that both are valid.
Like he said, \\ is a windows thing, and / works just as well.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2012-02-04 10:53:10

hi everyone

as some of you've saw the first title of vp had been released, but how to use more than one wavefile in the game?
and here is another thing, when i want to play the soundfile you'll hear when the game ends, the winner.wav file, after each right answer there opcurs an compilation error.

can somebody please give answers to both of these questions?

help will be appreciated

ciao

mike

Visit the following website to see what games we have:
http://www.nonvisiongames.com
Or the following English marketplace to see what retrogames and game merchandise I am selling:
https://www.retro-kingdom.com

2012-02-04 13:21:51

what kind of error you get, eg in which line, what.

He picked up the wrench and broke the guy’s wrist with it, one, and then the other wrist, two, and turned back and did the same to the guy who had held the hammer, three, four. The two men were somebody’s weapons, consciously deployed, and no soldier left an enemy’s abandoned ordnance on the field in working order.

2012-02-04 14:15:19

hi

@sid

when i add the code s.play(); in front of every line of the game i'll have the sound played there is just one compilation error, spread over different lines of hte game.
it is a expected expression value.
i don't know if i've typed the code s.play(); to much, that that is the case why it don't want to work.

note s is the name i've given the sound caller.
sound s;

i hope somebody could help me.

ciao

mike

Visit the following website to see what games we have:
http://www.nonvisiongames.com
Or the following English marketplace to see what retrogames and game merchandise I am selling:
https://www.retro-kingdom.com

2012-02-04 14:20:34

i think you have to stop the sound, or wait for it to stop by
play_wait()
function though i'm not sure.

but, you know, even if you go through the language tutorial even once,
and if you go through programming practice part 1,
i think you will understand it more clear

for doing programming, you have to grasp all basic concepts and work them out yourself, or otherwise if you ask on every char of your code this way, it could take you another 10000000000 years to develop a game, really.

He picked up the wrench and broke the guy’s wrist with it, one, and then the other wrist, two, and turned back and did the same to the guy who had held the hammer, three, four. The two men were somebody’s weapons, consciously deployed, and no soldier left an enemy’s abandoned ordnance on the field in working order.

2012-02-04 14:34:00

Every line? In that case, it would probably break up your if-else blocks. The most common cause for me getting an expected expression value error is something interfering with an if statement, so the else is not expected where it is found.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2012-02-04 15:24:38

Sid, in BGT you can use either one. You can use a standard forward slash or two backslashes to make a break between directories and files.

The point I wanted to raise is that its more common in programming to use a single forward slash rather than two backslashes for a couple of reasons. One its less typing, and other operating systems such as Mac OS or Linux will not accept a double backslash in a program and give you a file or folder not found error. So its just better practice to adopt a forward slash instead of double backslashes.

Understand using two backslashes is not wrong, especially on Windows, but you have to type a backslash, the standard escape character for programming, followed by a second backslash for the directory break. My thinking here is why do that when you can simplify it by using a single forward slash?

You can use either one in BGT as its more a matter of personal preference rather than being right or wrong. However, as I've been programming for roughly 12 years now I've found using a forward slash rather than the Microsoft Windows double backslashes more universal and less typing. Its also what professionals tend to call code safe, because you are less likely to make a mistake. Here is an example of what I mean.

Let's say you have to access a file several directories down like
Data\\Sounds\\Player\\Jump.wav
which has a total of six backslashes in that string. If you should miss even one backslash you will get a runtime error when you run your game. If you had used a forward slash like
Data/Sounds/Player/Jump.wav
you not only used three slashes instead of six backslashes, but you have less chance of making a mistake. Which is why I personally recommend not using backslashes.

mike, in order to add more sounds and music to the game all you have to do is declare more sound objects and initialize them. For example, below I will declare and initialize five sounds.

sound g_sound1;
sound g_sound2;
sound g_sound 3;
sound g_sound 4;
sound g_sound5;

void main ()
{

    // Load the sounds
    g_sound1.load ("Boom.wav");
    g_sound2.load ("gun.wav");
    g_sound3.load ("player.wav");
    g_sound4.load ("enemy.wav");
    sound5.load ("music.wav");
}

Basically, the entire point of object oriented programming is to be able to create as many objects as you need, in this case sounds, by calling the class name and creating a specific instance, an object, that represents the thing you need. In the program above I named the objects g_sound1 through g_sound5 but I could have given them specific names like g_boom, g_gun, g_player, g_enemy, and g_music so it would be less confusing as to which sound I'm referencing in my program. In fact, get into the habit of giving your objects good names because as your programs grow an object called s is going to be very obscure and hard to read when you have a game that is 20,000 lines long and contains a couple hundred objects and variables in use at any given time.

Plus in case you are wondering why I add a g_ before the object names that is a holdover from C and C++ programming to help the developer identify global variables from local variables. Local variables, temp variables inside the body of your function, are only temporary and just called boom, music, gun, etc, but a lot of professionals, myself included, append a g_ to global variables to help immediately identify that this program or script is calling a global variable and not a local/temp variable. Its certainly a case of personal preference, not mandatory, but just one of those things I've found extremely helpful in working with huge programs with thousands of lines of code with hundreds of objects and variables etc.

Sincerely,
Thomas Ward
USA Games Interactive
http://www.usagamesinteractive.com

2012-02-04 15:41:15

hi

@cae

i am understanding right now what the problem was. i believe that what you said is true. it disturbs the code blocks. as i've understood it on the right way.

@thomas

what you said makes the programming more clear. i never thought i should type oter sound ...; variables. thank you for pointing out to me and maybe others.

but it is clear to me why i only got sounds working at the end of the game. and why the sounds didn't work at the rest of the game.
i've accepted that the game is sapi voiced and at the end a sound.

thanks cae and thomas.

ooh yeah, before i forget:
@sid

i am currently busy with reading the manual carefully, but i can't promise that i won't come here with questions.

on this community are so many experienced bgt programmers and other programmers that it is very easy to get an answer on this way.
i've also learned a lot of the quiz game from jack. i've made a quiz in my own style.

view the releases forum for the last news about the game.

again, thank you very much.

ciao

mike

Visit the following website to see what games we have:
http://www.nonvisiongames.com
Or the following English marketplace to see what retrogames and game merchandise I am selling:
https://www.retro-kingdom.com

2012-02-04 16:32:09

Hi Thomas,

I know this was meant to be for beginners, but you'd agree with me when saying using an array there is more handy, right? At least I would...

And this brings me to another question, somewhat off topic but still.
This is also sort of directed towards Thomas, but any developer. When declaring sound objects, how do you name them?
What's your naming convention for variables?

For ScapeSkate, since it's folder structure is not too complicated and it doesn't have that many sounds, I split the sounds into categories, and had arrays of those different categories. So, a player-array for player sounds, Skateboard-array for skateboard sounds, environment, objects, jumps.

Just wanted to see how different coders do it. And this is where being one gets interesting. Everyone has their own style. big_smile

--
Talon
Wanna play my Games? Listen to my Music? Follow me on Twitter, and say hi~
Code is poetry.

2012-02-04 17:18:22

I use sound pools most of the time, heh. I use individual sound objects for background music, ambience, things like that, or for sounds that only play once, but require some manipulation while playing (like the cars or bats in DLE). Since those sounds are usually temporary, I usually just call them snd.
I really should load more things at the beginning, but .... that's... a lot of sounds...

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2012-02-04 18:44:39

Since battle zone was my first serious project, and the project where I learned most of the concepts I use now, I began by using a whole bunch of sound objects and classes. THe classes contained sound objects of their own, which is fine. I had arrays of those classes because it's easy to loop through arrays. But then, when the sound pool came along, I was busy converting everything to use the soundpool, and I broke battle zone, as the 12.9 version shows. FOr some reason when I kill an enemy, the pit sound disappears too lol. Ah well I'll have to fix that later. Now with damage extreme I use sound pools mstly, and I have integers in my arrays representing the slot I used.

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!

2012-02-06 20:54:50

Well, I guess it depends on the programming language in question and/or the complexity of the project being developed. If its a fairly simple project I'll just declare a few sound objects with descriptive names like g_shoot, g_jump, g_hit, etc so I know what sound I'm referencing. However, for bigger more serious projects I'll use a sound pool, an array of sounds, so its easier to manage them.

For example, in my game engine there is a class called Audio. Now, instead of declaring individual sound objects in the game code I reference the sound through an index, an array, so all I have to do is pass it a value like 1 through 199 or pass it a constant variable to reference the sound. Arrays are usually much easier than working with sounds individually because its easier to perform the same action by using loops etc. For example, in my game engine I can load several sounds at the same time just by using a for loop like this.

for (i = 1; i < 5; i++)
    g_audio.SoundOpen (i, "Data/Sounds/Mummy_Attack.wav");

In this simple example my SoundOpen() function references my sound pool in the Genesis Engine, and instead of having to type all of the load functions individually I can simply reduce it to a few loops like the one above. Obviously, if someone wanted to write one it would be easy enough to add this functionality to a BGT script and do essentially the same thing. For big projects it is far more handy than working with all of the sounds and sound objects on an individual basis.

This is just one more huge advantage of object oriented programming because you can create a class that does all the work behind the scenes and use it over and over and over again.

Sincerely,
Thomas Ward
USA Games Interactive
http://www.usagamesinteractive.com