2019-08-11 19:31:28

Hello! I am working on a bgt choose story game. The game runs just fine, but when i press a key it will do nothing, and the voice keeps speaking. Here is the code:

#include"dynamic_menu.bgt"
void main()
{
alert("hello you","This game is a chooseyour story game.");
show_game_window("Chooseyourstory v1.0");
dynamic_menu menu;
tts_voice voice;
menu.add_item_tts("Start the adventure, you can\'t currently load/save");
menu.add_item_tts("exit");
int result=menu.run("Choose an option with the arrow keys, press enter to activate.",true);
if(result==1)
{
start();
}
}
void start()
{
while(true)
{
tts_voice voice;

voice.speak_wait("Press a, b, or c, to choose an option while this is required.");
voice.speak_wait("You are currently in a house. You live with your dad. You are bored of your life, because you have never visited in an exciting adventure. What should you do? A: ask your fother. B: Go to the adventure! C: Stay at home with your dad.");
if(key_pressed(KEY_RETURN))
{
voice.stop();
}

wait(4000);

if(key_pressed(KEY_A))
{
ask();
}
}
}
void ask()
{
tts_voice voice;
voice.speak_wait("So you decided to ask your fother. You: Can i go to an adventure. Fother: Yep, with me. You: no no, i want to go alone! Fother: No! That just doesn\'t work. You go with me, or you stay at home. You: I don\'t want to stay in this fucking stupid house with you! Fother: Ok, it is my choice then, since you are using strong language, you will not go an adventure with me! You: Fuck you fother. The dad is a little crazy, and he pulls out his handgun. Then, boom! You are death!");
alert("Game over","You ended up dying at the very beginning. Very smart of you! Please try again with another option, i think that would be a good idea.");
}

Best regards: Marco

Thumbs up

2019-08-11 19:39:25 (edited by cat 2019-08-11 19:41:39)

this game is very crazy, wait are you say press a key it will do nothing? Try to create dlg.bgt, or DLG player BGT

Thumbs up

2019-08-11 20:27:14

I tried to fix it, but it will not work. After i choose the start option, it speaks the thing, but after that, it exits! Please someone help me, what am i doing wrong? Here is the code:

#include"dynamic_menu.bgt"
void main()
{
alert("hello you","This game is a chooseyour story game.");
show_game_window("Chooseyourstory v1.0");
dynamic_menu menu;
dynamic_menu menu1;

tts_voice voice;
menu.add_item_tts("Start the adventure, you can\'t currently load/save");
menu.add_item_tts("exit");
int result=menu.run("Choose an option with the arrow keys, press enter to activate.",true);
if(result==1)
{
voice.speak_wait("You are currently in a house. You live with your dad. You are bored of your life, because you have never visited in an exciting adventure. What should you do? A: ask your fother. B: Go to the adventure! C: Stay at home with your dad.");

int choose=menu1.run("choose",true);
menu1.add_item_tts("Ask to your dad");
menu1.add_item_tts("Go to the adventure!");
menu1.add_item_tts("Stay at home with your dad");
if(choose==1)
{
voice.speak_wait("So you decided to ask your fother. You: Can i go to an adventure. Fother: Yep, with me. You: no no, i want to go alone! Fother: No! That just doesn\'t work. You go with me, or you stay at home. You: I don\'t want to stay in this fucking stupid house with you! Fother: Ok, it is my choice then, since you are using strong language, you will not go an adventure with me! You: Fuck you fother. The dad is a little crazy, and he pulls out his handgun. Then, boom! You are death!");


}

alert("Game over","You ended up dying at the very beginning. Very smart of you! Please try again with another option, i think that would be a good idea.");
}
}

Best regards: Marco

Thumbs up

2019-08-11 20:46:08

Hi there,
@1: problem here is, that you're using too long pause between while iterations. 4000 ms, that means the key press will be checked every 4 seconds, and if you don't match them exactly with the press, it won't catch it.
As an experiment, try to hold the A key for 4 seconds. it should work, because of the interval.
Of course, this is probably not what you want, so,
I would:
1. lower the wait argument to a much smaller value, 100 should suit your needs quite well.
2. move it to the end of cycle, just for readability.
3. move the speak out of the cycle and make a key press option to repeat it, otherwise you'll get a very strange results.

Also, if your whole game will be in this format i.e. a scene description and press a, b, c or d, let me suggest something like this:

int get_choice(string message)
{
speak(message);

while (true)
{
if (key_pressed(KEY_R))
{
//R pressed, repeat the message
speak(message);
}
else if (key_pressed(KEY_A))
{
return 0;
}
else if (key_pressed(KEY_B))
{
return 1;
}
else if (key_pressed(KEY_C))
{
return 2;
}
else if (key_pressed(KEY_D))
{
return 3;
}

wait(100);
}
}

Now you have a much higher flexibility with presenting situations and choices. You can for example have a method for each game scene, like this:

void beginning_scene()
{
int choice=get_choice("You are currently in a house. You live with your dad. You are bored of your life, because you have never visited in an exciting adventure. What should you do? A: ask your fother. B: Go to the adventure! C: Stay at home with your dad.");

if (choice==0) //a
{
speak("So you decided to ask your fother. You: Can i go to an adventure. Fother: Yep, with me. You: no no, i want to go alone! Fother: No! That just doesn\'t work. You go with me, or you stay at home. You: I don\'t want to stay in this fucking stupid house with you! Fother: Ok, it is my choice then, since you are using strong language, you will not go an adventure with me! You: Fuck you fother. The dad is a little crazy, and he pulls out his handgun. Then, boom! You are death!");

end_game();
}
}

void end_game()
{
alert("Game over", "You have died. Well done guy, I have thought it will end like this.");
exit();
}

The speak function is just a function that will speak the text you pass in it, it isn't in bgt natively, you can replace it with your solution, or use for example something like this:

//speak.bgt
int sr=-1;
tts_voice voice;

void speak(string text, bool interrupt=true)
{
if (!screen_reader_is_running(sr))
{
bool set=false;
for (int i=1;i<=4;i++) {
if (screen_reader_is_running(i)) {sr=i; set=true; break;}
}
if (!set) sr=0;
}
if (sr!=0)
{
if (!interrupt) screen_reader_speak(sr, text); else screen_reader_speak_interrupt(sr, text);
}
else
{
if (!interrupt) voice.speak(text); else voice.speak_interrupt(text);
}
}

Get this whole thing just as an idea, I know you wasn't asking for it, but if it will save you work, I felt it worth mentioning.

Best regards

Rastislav

Thumbs up

2019-08-11 21:06:57

Simple addition to post 4, there's no reason you need to be waiting for 100 MS. I've waited no more than 5 MS in my loops, context being an extremely high traffic online game.
Remember, the wait function pauses your entire script. Even a small value such as 100 Ms is way way too long unless you have a specific reason, in which case you should probably be using timers anyway so background operations aren't interrupted. As stated in the BGT docs...

docs wrote:

It is thus not advisable to wait for a long time in situations where the program needs to be responsive. However, waiting for about 5 milliseconds in your main game loop as well as other loops that run for a long time is highly recommended, as it reduces the CPU usage of your program enormously without affecting its speed. If you fail to do this, your game will consume 100 % of the CPU at all times.

Thumbs up

2019-08-12 04:57:22

there's no wile loop. that's why it exits

If you would like to talk to me, you can add me on skype @ live:adelspence2004.
and if you wanna folow me on twitter, you can ad [email protected] Spence
and if you wanna join me discord server, you can join
https://discord.gg/dP4CvT

Thumbs up

2019-08-12 15:26:28

Also, the reason your first bit of code fails so badly is because you're calling the tts.speak function inside the while loop. What you'll want to do is call the tts_speak function and speak the text first, then enter the while loop where you check for key presses and what not.

Use the below link to get about 500 or so mb of extra dropbox space when you create an account.
https://db.tt/dDngEzFLo7