Legacy GM Question Programming- SOUND & TEXT

P

PabloDiez

Guest
Hello. Im trying to do some sort of undertale-like dialogue in which characters talk to the protagonist through textboxes. Thing is I have recorded the lines of the characters because I want their lines to be heard at the same time they are appearing on-screen... but i dont know how to insert the audio in the game. I also need that when a text finishes and the player presses enter, the first audio weve been hearing stops and then the next one starts to sound.
All the textbox coding is done. The thing I need help with is the audio that accompanies it. The voices that read the text outloud.
Ive tried and tried but ive got no idea how to do it. If anyone would be so kind as to help me Id be forever grateful.
Thanks in advance
 
P

PabloDiez

Guest
Yes but I don't know where to put it. In which condition would you put it considering you wanted an audio to play for each "text[ ]"?
Sorry if this is too silly to ask but Im relatively new to the program.
Thanks a lot for answering
 
P

PabloDiez

Guest
Did you try audio_play_sound(); ?
Yes but I don't know where to put it. In which condition would you put it considering you wanted an audio to play for each "text[ ]"?
Sorry if this is too silly to ask but Im relatively new to the program.
Thanks a lot for answering
 

Kahrabaa

Member
Yes, use audio_play_sound(); when the each message starts, you need to keep a list of wich line will play at start of a message.

Also audio_play_sound(); returns the ID of that sound that played.
So you need to get the ID, then stop it when the player presses enter.
Like this:
currentSound = audio_play_sound( speech );
Then to stop
audio_stop_sound( currentSound );
And then start the next.
 
P

PabloDiez

Guest
Yes, use audio_play_sound(); when the each message starts, you need to keep a list of wich line will play at start of a message.

Also audio_play_sound(); returns the ID of that sound that played.
So you need to get the ID, then stop it when the player presses enter.
Like this:
currentSound = audio_play_sound( speech );
Then to stop
audio_stop_sound( currentSound );
And then start the next.
Million thanks. Now I encounter another problem... when the first sound finishes, the second keeps reproducing each time I press enter. In my case I programmed the textbox so that with the first time the player pressed enter, the text would appear completed if it hadnt finished already, and then, after the second time he pressed enter, wed jump to the next text.
The idea is that with the first time clicking enter the first audio would stop, and with the second time we pressed, the next audio would begin. I used alarms and I managed to make the first audio start and stop, and the second starts when it has to, but then... it keeps reappearing.

I'll insert the code I used:
(PRESS "ENTER")
if (audio_is_playing(snd_play)==true)
{
audio_stop_sound(snd_play)
alarm [1] = 20;
}
else
{
snd_play2 = true;
snd=audio_play_sound(snd_prueba2,10,false);

}
if (audio_is_playing(snd_play2)==true)
{
audio_stop_sound(snd_play2)
alarm [1] = 20;
}

(RELEASE ENTER)
if alarm [1]>-1
and keyboard_check (vk_enter)
{
snd_play2 = true;
snd=audio_play_sound(snd_prueba2,10,false);
}

if alarm [2]>-1
and keyboard_check (vk_enter)
{
snd_play3 = true;
snd=audio_play_sound(snd_prueba3,10,false);
}

Thanks a lot for answering
 
Last edited by a moderator:

Kahrabaa

Member
Sorry, I got confused from your code because you havent given enough information.
example how can keyboard_check(vk_enter) be inside (RELEASE ENTER) event? If the enter key is released then it is never pressed.

Also what are these variables used for?
snd_play2 = true;
snd_play3 = true;

when the first sound finishes, the second keeps reproducing each time I press enter.
When you press enter and the first sound is finished, this is what you wrote will happen.
Code:
else
{
snd_play2 = true;
snd=audio_play_sound(snd_prueba2,10,false); //is it this sound that plays?

}
 
P

PabloDiez

Guest
Sorry, I got confused from your code because you havent given enough information.
example how can keyboard_check(vk_enter) be inside (RELEASE ENTER) event? If the enter key is released then it is never pressed.

Also what are these variables used for?
snd_play2 = true;
snd_play3 = true;


When you press enter and the first sound is finished, this is what you wrote will happen.
Code:
else
{
snd_play2 = true;
snd=audio_play_sound(snd_prueba2,10,false); //is it this sound that plays?

}
Exactly. The sn_play are the different audios. I tried separating them instead of making one variable in the hope that this way id be able to make them stop and start one by one. Deeply sorry for my coding mistakes, Im learning still.
The problem is in the else part, ain't it? what should I write instead ?
Again million thanks por putting up with me. Very sorry if what Im asking is too weird.
 
P

PabloDiez

Guest
Sorry, I got confused from your code because you havent given enough information.
example how can keyboard_check(vk_enter) be inside (RELEASE ENTER) event? If the enter key is released then it is never pressed.

Also what are these variables used for?
snd_play2 = true;
snd_play3 = true;


When you press enter and the first sound is finished, this is what you wrote will happen.
Code:
else
{
snd_play2 = true;
snd=audio_play_sound(snd_prueba2,10,false); //is it this sound that plays?

}
Writing the keyboard_check inside the release event was an attempt I made to allow me to have silence if I pressed "enter" the first time and cut the first audio before it finished. Then, when I pressed enter again, the second audio would come up. I guess by your answer that this is rather uncommon and incorrect, isn't it? That did work, if I may say in my defense haha
 

Kahrabaa

Member
No problem man,No need to defend hehe Im not attacking you xD
Im just tossing ideas and you need to understand and fix this yourself.

You need only 1 sound playing at a time right? Then it is enough with only 1 variable.
current_sound = audio_play_sound( snd_play); //Store ID of the sound into this variable
then if you do
audio_stop_sound(current_sound);
No matter wich sound is playing will be stopped.

Right now when you do
snd_play2 = true;
If snd_play2 really is the name of the sound in the resource list to your left, then this will do nothing, because snd_play2 is really an ID used by gamemaker, you cannot change it

This is how I would do this in theory.


CREATE EVENT:
Code:
currentMessage=0;  //Keep track of what message we are on
currentSound=-1; //This will hold the ID of the sound thats playing

//Prepare a list of all sounds that will be connected to each message
sound[0] = snd_play;
sound[1] = snd_play2;
sound[2] = snd_play3;
WHEN YOU PRESS ENTER:
Code:
audio_stop_sound( currentSound );
currentMessage += 1; //Go to next message
currentSound = audio_play_sound( sound[ currentMessage ] ); //play the sound of next message and remember what sound was played, the sound played is based on the list we setup in CREATE event. sound[ currentMessage ].
Then you would not have to make alot of IF's for each sound.
Hope this helped.
 

woods

Member
taking a wild stab in the dark here... wouldnt the basic structure go something like this?

Code:
// play sound when text1 is started
if (textbox_A=true)
{
// insert code to draw textbox here
audio_play_sound(snd_1,10,false);
if keyboard_check_pressed(vk_enter)
     {
     audio_stop_sound(snd_1);
     audio_play_sound(snd_2);
     }
}
repeat for each textbox and sound that accompanies it
 
Top