Topic: no idea why this isn't working

Hi all, for some reason, the error sound won't play when I call it from the main menu. here is all of my code. Any ideas? Please poitn out anyting else that is wrong as well
Cheers
#include "dynamic_menu.bgt"
#include "sound_pool.bgt"
int walk_slot;
int walk_sound=random(1,9);
int brick_sound;
int pile_sound;
int scor;
int start_po;
const int left=-1;
const int right=1;
int end_po=20;
int p_p;
int brick_lo;
int pile_lo;
tts_voice voice;
timer walk_timer;
timer game_timer;
sound menu_music, level_music, error_sound, intro, bye, load_music, load_speach;
sound_pool pool;
bool game_over;
bool near_pile;
bool near_bricks;
dynamic_menu my_menu;
void game_loop()
{
while (scor>= 50 or game_timer.elapsed<= 120000)
{
start_state();
keyboard();
wait(5);
}
}
void keyboard()
{
if (key_pressed(KEY_ESCAPE))
{
main_menu();
}
if (key_pressed(KEY_C))
{
voice.speak("your score is" +scor);
}
if (key_pressed(KEY_LEFT))
{
if (p_p==start_po)
{
voice.speak ("ok, you are at the start of the grid");
}
else
{
walk(left);
}
}
if (key_pressed(KEY_RIGHT))
{
if (p_p==brick_lo)
{
voice.speak("your at the brick, pick it up");
}
else
{
walk(right);
}
}
if (key_pressed(KEY_UP))
{
if (p_p==brick_lo)
{
voice.speak("picked up");
}
else
{
voice.speak("yo, you arn't anywear near the stuff. walk to the right to get nearer to it");
}
}
}
void start_state()
{
game_over=false;
near_pile=true;
near_brick=false;
pile_lo=0;
brick_lo=20;
scor=0;
p_p=1;
}
void walk(int dir)
{
if (dir==left)
{
if (p_p==start_po)
{
return;
}
else
{
walk_sound=pool.play_stationary("sounds/steps/walk"+walk_slot+".wav", false);
p_p--;
}
}
if (dir==right)
{
if (p_p==end_po)
{
return;
}
else
{
walk_sound=pool.play_stationary("sounds/steps/walk"+walk_slot+".wav", false);
p_p++;
}
pool.update_listener_1d(p_p);
}
}
void main_menu()
{
int menu_chois;
menu_music.play_looped();
my_menu.reset(true);
my_menu.wrap=false;
my_menu.allow_escape=false;
my_menu.add_item("sounds/menu/start game.wav", false);
my_menu.add_item("sounds/menu/listen_instructions.wav", false);
my_menu.add_item("sounds/menu/check_speakers.wav", false);
my_menu.add_item("sounds/menu/exit.wav", false);
menu_chois=my_menu.run_extended("sounds/menu/menu prompt.wav", false, 1, true);
if (menu_chois==1)
{
menu_music.stop();
game_loop();
}
if (menu_chois==2)
{
error_sound.play_wait();
alert("wait", "not implimented yet");
}
if (menu_chois==3)
{
error_sound.play_wait();
alert("wait", "not implimented yet");
}
if (menu_chois==0 or (menu_chois==4))
{
bye.play();
while(bye.playing==true)
{
if (key_pressed(KEY_RETURN))
{
bye.stop();
exit();
}
}
wait(5);
exit();
}
}
void main()
{
show_game_window("brick pile. ");
install_keyhook();
intro.load("sounds/intro.wav");
intro.play();
while(intro.playing==true)
{
if (key_pressed(KEY_RETURN))
{
intro.stop();
wait(5);
}
}
load_music.load("sounds/loadmusic.wav");
load_music.volume=-10;
load_music.play_looped();
load_speach.load("sounds/loading.wav");
load_speach.play();
menu_music.load("sounds/menumusic.wav");
menu_music.volume=-10;
level_music.load("sounds/levelmusic.wav");
error_sound.load("sounds/error.wav");
bye.load("sounds/goodbye.wav");
wait(10000);

load_music.stop();
main_menu();
}

Re: no idea why this isn't working

At first glance, it sounds like an unintentional mistake in the file name spelling (for instance, check the case of the sound file name) or an unsupported wave format used. I believe you have checked these but I can't think of any other reason off the top of my head.
Lukas

3 (edited by joshock 2016-08-24 03:34:24)

Re: no idea why this isn't working

Awesome, the format was the issue. I was wondering, what the most streight foward way of creating objects, lets say, in this kace, the brick, and the brick pile that I would be adding bricks to. Not sure if this is making any sence. I sure hope it makes some. Lol. Would I use classes? And have an int within each class for counting bricks added? And I'm assuming sound playback for the bricks, and brick pile owuld have to happen within that class correct? Thanks for all the patients
and help
Chears

Re: no idea why this isn't working

Hi,
glad you found that out. So does the sound work now?

As for the bricks and piles, you might probably use classes. Depends on how exactly you want these mechanics to work. I'm not exactly sure what you want to happen in the game. If you described this a little further, I would be able to imagine the layout of the game better and thus suggest what solution is the most relevant in my opinion.

Thanks,
Lukas

Re: no idea why this isn't working

Hi, actually, before we get to the classes, I'm having an issue still with writing a proper walk function. Right now the compiler is flagging saying there is an error On line: 92 (1)
Information: Compiling void walk(int)

On line: 102 (63)
Line: walk_slot=pool.play_stationary("sounds/steps/walk"+random(1,9)".wav", false);
Error: Expected ')' or ','
I've check around that erea to see if I have a quotation or Parentheses  missing, but can't find it. What am I missing? Code below. Thanks for all the help
Chears
#include "dynamic_menu.bgt"
#include "sound_pool.bgt"
int walk_slot;
int brick_sound;
int pile_sound;
int scor;
int start_po=0;
const int left=-1;
const int right=1;
int end_po=20;
int p_p;
int brick_lo;
int pile_lo;
tts_voice voice;
timer walk_timer;
timer game_timer;
sound menu_music, level_music, error_sound, intro, bye, load_music, load_speach, sp_test;
sound_pool pool;
bool game_over;
bool near_pile;
bool near_brick;
dynamic_menu my_menu;
void game_loop()
{
while (scor>= 50 or game_timer.elapsed<= 120000)
{
level_music.play_looped();
start_state();
keyboard();
wait(5);
}
}
void keyboard()
{
if (key_pressed(KEY_ESCAPE))
{
level_music.stop();
main_menu();
}
if (key_pressed(KEY_C))
{
voice.speak("your score is" +scor);
}
if (key_pressed(KEY_LEFT))
{
if (p_p==start_po)
{
voice.speak ("ok, you are at the start of the grid");
}
else
{
walk(left);
}
}
if (key_pressed(KEY_RIGHT))
{
if (p_p==brick_lo)
{
voice.speak("your at the brick, pick it up");
}
else
{
walk(right);
}
}
if (key_pressed(KEY_UP))
{
if (p_p==brick_lo)
{
voice.speak("picked up");
}
else
{
voice.speak("yo, you arn't anywear near the stuff. walk to the right to get nearer to it");
}
}
if (key_pressed(KEY_Z))
{
voice.speak(p_p);
}
}
void start_state()
{
game_over=false;
near_brick=false;
near_pile=true;
pile_lo=0;
brick_lo=20;
scor=0;
p_p=1;
}
void walk(int dir)
{
if (dir==left and p_p==0 and walk_timer.elapsed>350)
{
p_p++;
walk_slot=pool.play_stationary("sounds/bump.wav", false);
}
else
{
p_p--;
walk_slot=pool.play_stationary("sounds/steps/walk"+random(1,9)".wav", false);
}
if (dir==right and p_p==20 and walk_timer.elapsed>350)
{
p_p--;
walk_slot=pool.play_stationary("sounds/bump.wav", false);
}
else
{
p_p++;
walk_slot=pool.play_stationary("sounds/steps/walk"+random(1,9)".wav", false);
}
walk_timer.restart();
pool.update_listener_1d(p_p);
}
void main_menu()
{
int menu_chois;
menu_music.play_looped();
my_menu.reset(true);
my_menu.wrap=false;
my_menu.allow_escape=true;
my_menu.add_item("sounds/menu/start game.wav", false);
my_menu.add_item("sounds/menu/listen_instructions.wav", false);
my_menu.add_item("sounds/menu/check_speakers.wav", false);
my_menu.add_item("sounds/menu/exit.wav", false);
menu_chois=my_menu.run_extended("sounds/menu/menu prompt.wav", false, 1, true);
if (menu_chois==1)
{
menu_music.stop();
game_loop();
}
if (menu_chois==2)
{
error_sound.play_wait();
main_menu();
}
if (menu_chois==3)
{
menu_music.stop();
sp_test.play();
while(sp_test.playing==true)
{
if (key_pressed(KEY_RETURN))
{
sp_test.stop();
main_menu();
}
}
main_menu();
}
if (menu_chois==0 or (menu_chois==4))
{
bye.play();
while(bye.playing==true)
{
if (key_pressed(KEY_RETURN))
{
bye.stop();
exit();
}
}
wait(5);
exit();
}
}
void main()
{
show_game_window("brick pile");
install_keyhook();
intro.load("sounds/intro.wav");
intro.play();
while(intro.playing==true)
{
if (key_pressed(KEY_RETURN))
{
intro.stop();
wait(5);
}
}
wait(3000);
load_music.load("sounds/loadmusic.wav");
load_music.volume=-10;
load_music.play_looped();
load_speach.load("sounds/loading.wav");
load_speach.play();
menu_music.load("sounds/menumusic.wav");
menu_music.volume=-10;
level_music.load("sounds/levelmusic.wav");
level_music.volume=-10;
error_sound.load("sounds/error.wav");
bye.load("sounds/goodbye.wav");
sp_test.load("sounds/speaker_test.wav");
wait(7000);
load_music.stop();
main_menu();
}

Re: no idea why this isn't working

Thankfully, this particular error is easy to spot and fix, and does in deed belong just to this single line of code. It doesn't affect or is not affected by any other part of the code base, as so often happens. :-)

You're missing just one more plus sign. Look at the offending line once again:

walk_slot=pool.play_stationary("sounds/steps/walk"+random(1,9)".wav", false);

It should be the following:

walk_slot=pool.play_stationary("sounds/steps/walk"+random(1,9)+".wav", false);

That should do the trick.
Lukas

Re: no idea why this isn't working

Hi there, Thanks so much for the help. The program runs now, but the walk function still isn't working correctly. When I press right to move right, I here all the walk sounds play at once and when I check to see if p_p has changed, it hasn't. Here is the code for the walk function again, with the corrections. also including keyboard as well if you need it.
Thanks so much for all your help
cheers
void walk(int dir)
{
if (dir==left and p_p==0 and walk_timer.elapsed>350)
{
p_p++;
walk_slot=pool.play_stationary("sounds/bump.wav", false, true);
}
else
{
p_p--;
walk_slot=pool.play_stationary("sounds/steps/walk"+random(1,9)+".wav", false, true);
}
walk_timer.restart();
if (dir==right and p_p==20 and walk_timer.elapsed>350)
{
p_p--;
walk_slot=pool.play_stationary("sounds/bump.wav", false, true);
}
else
{
p_p++;
walk_slot=pool.play_stationary("sounds/steps/walk"+random(1,9)+".wav", false, true);
}
walk_timer.restart();
pool.update_listener_1d(p_p);
}
here is keyboard too if you need it
void keyboard()
{
if (key_pressed(KEY_ESCAPE))
{
level_music.stop();
main_menu();
}
if (key_pressed(KEY_C))
{
voice.speak("your score is" +scor);
}
if (key_down(KEY_LEFT))
{
if (p_p==start_po)
{
voice.speak ("ok, you are at the start of the grid");
}
else
{
walk(left);
}
}
if (key_down(KEY_RIGHT))
{
if (p_p==brick_lo)
{
voice.speak("your at the brick, pick it up");
}
else
{
walk(right);
}
}
if (key_pressed(KEY_UP))
{
if (p_p==brick_lo)
{
voice.speak("picked up");
}
else
{
voice.speak("yo, you arn't anywear near it. walk to the right to get nearer to it");
}
}
if (key_pressed(KEY_Z))
{
voice.speak(p_p);
}
}

Re: no idea why this isn't working

Here is your walk function, simplified, commented and hopefully bug free for the time being. :-)

void walk(int dir)
{
if (walk_timer.elapsed < 350) return;
walk_timer.restart();
// This essential check can be done just once at the very beginning of the function. This way, the timer and walking speed has been taken care of for good and won't be bothering us in any subsequent ifs.
if (dir==left)
{
if (p_p==0)
{
p_p++;
// Why do you do that when the player bumps into the wall? If I understand it correctly, the current implementation, where you increment p_p by 1 here, would actually bump into the wall and immediately move the player one step to the right away from it. Is this what you want?
walk_slot=pool.play_stationary("sounds/bump.wav", false, true);
// Does the walk_slot in the sound_pool actually need to be persistent? To me, it would seem like it doesn't. It should in fact be more beneficial if it was not. Persistent sounds are good for longer audio like music, ambiences, character vocals, possibly cut scenes, etc. Non-persistent sounds used for short, semi-randomly triggered, unpredictable and ever changing dynamic audio, like bumping into a wall, footsteps or gunshots, etc, are actually one of the main strengths of the sound_pool. So, if it doesn't in fact have to be persistent for a good reason, I would recommend simply leaving out the second boolean entirely.
}
else
{
p_p--;
walk_slot=pool.play_stationary("sounds/steps/walk"+random(1,9)+".wav", false, true);
// Same as above regarding the sound's persistency.
}
}
else if (dir==right)
{
if (p_p==20)
{
p_p--;
// Same as above regarding bumping into the wall and moving one step away from it in the opposite direction.
walk_slot=pool.play_stationary("sounds/bump.wav", false, true);
// Same as above regarding the sound's persistency.
}
else
{
p_p++;
walk_slot=pool.play_stationary("sounds/steps/walk"+random(1,9)+".wav", false, true);
// Same as above regarding the sound's persistency.
}
}
pool.update_listener_1d(p_p);
}

Hope this works,
Lukas

Re: no idea why this isn't working

Hi, I haven't tested this code yet but I will soon. Can you tell me what I was doing that was causing the function to fail?

Re: no idea why this isn't working

First of all, your ifs were not structured properly, as long as I remember correctly. The logical branching was not exactly correct and there were some cases that were not counted for.

If I remember right, you had something like the following line in there:

if (direction == left and p_p == 0 and walk_timer.elapsed > 350)

This would work, except that afterwards there was just a single else. Basically, bump into the wall if I'm standing at the edge, trying to move left, and enough time has elapsed. Else, walk left as though there was some room. So, if I  was trying to move left but the other two conditions were false, the game would still attempt to walk to the left, off the edge of the board.

Also, I think you didn't check the value of the timer again in any more of the following ifs.

Lukas

Re: no idea why this isn't working

an easy mistake to make smile
something I know I've done more than once sad