Topic: memory train tutorial question

Hello everyone,
I hope that someone here will be able to assist me.
I am new to the bgtk and fairly new to programming as well. I have dabbled with the scripting language in vipMud however this is my first time jumping into a more versatile scripting language.
I have been reading the manual and the language tutorial. I went to work on the first program, which is a game called memory train.
I first wrote out all the code so that I could better assimilate the information. when I tried running it however, I was having a problem. I then decided to try pasting all he snippets from the tutorial. I did this and the game starts however I have one serious problem. Pressing the arrow keys doesn't do anything in the dynamic menu. I pasted it exactly as the manual had it but it won't let me arrow through the menu to choose either to start a game or practice mode etc.
sapi says, the welcome message and tells me I can use my arrow keys to look at the options but nothing works. I tried pressing escape also and it won't exit the program either. The only way I am able to exit the game is through the windows task manager. Once I do this, the bg toolkit throws an error because I had to end an unresponsive program.
at first, I thought the problem may be because I am running windows in a virtual machine on my MacBook pro. I sent it to my husband though, who is using a windows desktop and he had the same difficulty.
we are both running a 64 bit version of Windows 7. does anyone have any ideas as to what is going on? and why the code that is pasted exactly from the documentation isn't working?
Any assistance would be appreciated. I am brand new at this but would love to learn.
take care,

Re: memory train tutorial question

Hi,
the exact cause of the problem is hard to tell just from this description. Even when you have pasted all the code snippets exactly as laid out in the tutorial, it's still possible that you have unintentionally caused something not to work as expected because even the linear order of the code can matter a great deal in some cases.
Could you perhaps copy paste the entire contents of your current code here, exactly as is? That should help a lot.
Thanks,
Lukas

Re: memory train tutorial question

I don't seem to be allowed to post the code. How can I show you?

Re: memory train tutorial question

I'm not sure how to fix this problem, sorry. For some reason, I've never had it myself but I seem to remember that others have reported the forum getting in the way of posting code by trying to interpret some of the symbols as BB Code.
If someone knows the workaround, please publish it.
Thanks,
Lukas

Re: memory train tutorial question

Hello,
Firstly, to do that, I believe you enclose the block of code in code tags.
Replace the parens below with brackets.
(code)
code goes here.
(/code)
Although, if you are using JAWS for windows, the ishue might be that JAWS is grabbing all the keys you type before they reach bgt. To fix this, you should install a keyhook by doing something like this:

if(screen_reader_is_running(JAWS))
{
install_keyhook();
}
Have a nice day,
Lucas

Re: memory train tutorial question

Thanks for this. I will post the code elow. I am just working off of the tutorial games. I am brand new to this and these exercises help.
Thanks in advanced for all the assistance.

 
#include "dynamic_menu.bgt"

sound music;
sound error_sound;
sound[] tone(4); 

void main()
{
tone[0].load("1.wav");
tone[0].volume = -10;
tone[1].load("2.wav");
tone[1].volume = -10;
tone[2].load("3.wav");
tone[2].volume = -10;
tone[3].load("4.wav");
tone[3].volume = -10;
error_sound.load("error.wav");
error_sound.volume = -10;
music.load("music.wav");
music.volume = -10;
tts_voice voice;
dynamic_menu menu;
menu.allow_escape = true;
menu.wrap = true;
menu.add_item_tts("Start game");
menu.add_item_tts("Keyboard practice");
menu.add_item_tts("Exit game");
show_game_window("Memory Train");
voice.speak_wait("Welcome to Memory Train!");
music.play_looped();

int choice; 
do
{
choice = menu.run("Please choose a menu item with the arrow keys, then hit enter to activate it.", true);
if(choice==1)
{
music.stop();
play_round(); 
music.play_looped();
}
else if(choice==2)
{
music.stop();
keyboard_practice(); 
music.play_looped();
}
}
while(choice!=0 and choice!=3);
voice.speak_wait("Thanks for playing.");
} 
void keyboard_practice()
{
tts_voice voice;
voice.speak_wait("Press the arrow keys to find out which key generates which tone.");
voice.speak_wait("Press escape to stop practicing.");
while(!key_pressed(KEY_ESCAPE))
{
if(key_pressed(KEY_LEFT))
{
play_tone(0);
}
else if(key_pressed(KEY_DOWN))
{
play_tone(1);
}
else if(key_pressed(KEY_RIGHT))
{
play_tone(2);
}
else if(key_pressed(KEY_UP))
{
play_tone(3);
}
wait(5);
}
} 
void play_tone(int i)
{
tone[i].stop();
tone[i].play();
} 
void play_round()
{bool game_over = false; 
int[] sequence; 
int sequence_length = 0;
float time_between_tones = 500; 
float time_between_inputs = 2000; 
do
{

sequence_length++;
sequence.resize(sequence_length);
sequence[sequence_length-1] = random(0,3);output_sequence(@sequence, time_between_tones);game_over = input_sequence(@sequence, time_between_inputs);if((sequence_length%5) == 0)
{
time_between_tones = time_between_tones*0.9;if(time_between_tones < 150)
{
time_between_tones = 150;
}
}
}
while(!game_over);
int score = sequence_length-1; 
tts_voice voice;
voice.speak_wait("Your final score was " + score);
} 
void output_sequence(int[]@ sequence, float time_between_tones)
{
timer clock;
int current;
for(uint i=0; i<sequence.length(); i++)
{if(i>0)
{
clock.restart();
while(clock.elapsed < time_between_tones)
{
wait(5);
}
}
current = sequence[i];
play_tone(current);
}while(tone[current].playing)
{
wait(5);
}
} 
bool input_sequence(int[] @sequence, float time_between_inputs)
{
timer clock;
for(uint i=0; i<sequence.length(); i++)
{clock.restart();
int input = -1; 
while(clock.elapsed < time_between_inputs)
{
if(key_pressed(KEY_LEFT))
{
input = 0;
}
else if(key_pressed(KEY_DOWN))
{
input = 1;
}
else if(key_pressed(KEY_RIGHT))
{
input = 2;
}
else if(key_pressed(KEY_UP))
{
input = 3;
}
if(input>=0)
{
break; 
}
wait(5);
}if(input!=sequence[i])
{
error_sound.play_wait();
return true;
}play_tone(input);
}clock.restart();
while(clock.elapsed < 1000)
{
wait(5);
}
return false;
}

Re: memory train tutorial question

Ok, thanks for the code. What errors is it showing now?
Lukas

Re: memory train tutorial question

I don't receive any actual error. However, when I try to arrow up and down through the options, nothing is spoken. The music plays. I get the welcome to memory train message where it tells me to arrow up and down. but when I try to arrow up and down nothing happens. I can't even escape out of the windows. The only way I can close it is by ending the task in the task manager.

Re: memory train tutorial question

Hi,
Again, are you using JAWS? Because that might be your ishue. In order for bgt to work with JAWS, you need to install a keyhook. In post 5 I give an example of how you could do that. I would place that code in your main function at the beginning.

Have a nice day,
Lucas

Re: memory train tutorial question

Thank you, this fixed it. Sorry for the late response. I have family in town so was away from the computer for a while. I assume that I would have to do something for every possible screen reader if I were to have a game for public use? Or, is jaws the only one that requires a hook.

Re: memory train tutorial question

You might detect the installed screen reader and do specific things if needed for the selected screen reader, at the beginning of your program smile

Re: memory train tutorial question

However, that said, Jaws is the only screen reader known to intercept keystrokes for its own purposes before passing them through to the specific application you are currently using. That's the one and only reason why the keyhook functions were added to BGT. So, to sum this up, as far as I know, you don't need to do anything else for any other screen reader besides installing the keyhook on game startup. You don't even need to uninstall it manually any more - if BGT detects that the keyhook has been installed, it will uninstall it automatically on exit.
Hope this helps,
Lukas

Re: memory train tutorial question

Ah, Memory Train. The most I was ever able to do is get the menu to play and Keyboard Practice to work, although it would exit the game completely when I hit escape instead of going to the menu. I guess I forgot to include that bit in my code. Of course it's been a long time since I really sat down with it so I unfortunately don't remember all I learned.

Focus your powers and prepare for buttle.