2015-07-08 13:25:56

hello, today I was messing around with the example games shown in the bgt help system. However when I got to the point in a test thingy that I was working on where I had to define what the menu options did, I got compilation errors left and right. I tried all sorts of ways to fix them, looked through the part of the script that broak the game about 3 times looking for any errors with end statements and parenthesies and what not but couldn't find anything. I tried moving sections of code around but the errors didn't really change. I'll post both all of the code and the errors here.
code.
#include "dynamic_menu.bgt"
sound music;
sound error;
sound[] tone(4);
int menu_choice;
void main()
{
tone[0].load("1.wav");
tone[1].load("2.wav");
tone[2].load("3.wav");
tone[3].load("4.wav");
error.load("error.wav");
music.load("music.wav");
music.volume=-10;
tts_voice voice;
show_game_window("swamp Memmory");
voice.speak_wait("wellcome to swamp memmory, made from the test game example in the bgt help system.");
music.play_looped();
dynamic_menu menu;
menu.add_item_tts("start getting bashed");
menu.add_item_tts("practice being bashed");
menu.add_item_tts("chicken out");
menu.allow_escape=true;
menu.wrap=true;
menu.run("here to get hit all over the place? well, this is a very good place to start!", true);
do
{
menu_choice=menu.run("here to get hit all over the place? well, this is a very good place to start!", true);
if(menu_choice==1)
{
music.stop();
play_round();
music.play_looped();
}
else if(menu_choice==2)
{
music.stop();
keyboard_practice();
music.play_looped();
}
}
while(menu_choice!=0 and menu_choice!=3);
voice.speak_wait("ur, where do you think you're going? the zombies haven't had their dayly brain needs met oh well if you really want to go then, good bye.");
}
errors.
File: C:\Users\andawn\Documents\random bgt scripts for messing around\test project\Swamp simon.bgt
On line: 6 (1)
Information: Compiling void main()

File: C:\Users\andawn\Documents\random bgt scripts for messing around\test project\Swamp simon.bgt
On line: 32 (1)
Line: play_round();
Error: No matching signatures to 'play_round()'

File: C:\Users\andawn\Documents\random bgt scripts for messing around\test project\Swamp simon.bgt
On line: 38 (1)
Line: keyboard_practice();
Error: No matching signatures to 'keyboard_practice()'

from the errors here, my closest guess is that I haven't defined the functions "play_round" and "keyboard_practice" yet. But when defining them, I also wouldn't know where to put the code for those functions. Sinse putting them at the bottum would make the script a lot messier and putting so much code into an if statement also doesn't seem logical.

I used to be a knee like you, then I took an adventurer in the arrow.

2015-07-08 17:20:54

Yeah, it's complaining about the missing functions. A neat trick I've discovered over the years - you can define the functions just with the expected signature and no code at all between the left and right brace. It will go through the compiler and you can test what code you already have that way, writing the actual code of the functions in question later on.

The actual placement of the functions is totally up to you; they can be anywhere you can think of, at the top of the script, at the bottom, in the middle, inside an include you create, the only point where a function declaration cannot be located is inside another function, unlike some other languages. That means that declaring a function inside an if statement or a loop wouldn't work either, anyway.
Hope this helps,
Lukas

I won't be using this account any more or participating in the forum activity through other childish means like creating an alternate account. I've asked for the account to be removed but I'm not sure if that's actually technically possible here. Just writing this for people to know that I won't be replying, posting new topics or checking private messages until the account is potentially removed.

2015-07-08 17:53:06

when defining the function for keyboard practice, the following happened.
code:
#include "dynamic_menu.bgt"
sound music;
sound error;
sound[] tone(4);
int menu_choice;
tts_voice voice;
void main()
{
tone[0].load("1.wav");
tone[1].load("2.wav");
tone[2].load("3.wav");
tone[3].load("4.wav");
error.load("error.wav");
music.load("music.wav");
music.volume=-10;
show_game_window("swamp Memmory");
voice.speak_wait("wellcome to swamp memmory, made from the test game example in the bgt help system.");
music.play_looped();
dynamic_menu menu;
menu.add_item_tts("start getting bashed");
menu.add_item_tts("practice being bashed");
menu.add_item_tts("chicken out");
menu.allow_escape=true;
menu.wrap=true;
menu_choice=menu.run("here to get hit all over the place? well, this is a very good place to start!", true);
do
{
if(menu_choice==1)
{
music.stop();
music.play_looped();
}
else if(menu_choice==2)
{
music.stop();
void keyboard_practice()
{
voice.speak_wait("press any of the 4 arrow keys to find out which swamp zombie normal, tyrant, giant or amorphis is attacking you.");
voice.speak_wait("press escape if you are done hitting arrow keys.");
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);
}
}
music.play_looped();
}}
}
while(menu_choice!=0 and menu_choice!=3);voice.speak_wait("ur, where do you think you're going? the zombies haven't had their dayly brain needs met oh well if you really want to go then, good bye.");
}
errores:
File: C:\Users\andawn\Documents\random bgt scripts for messing around\test project\Swamp simon.bgt
On line: 64 (1)
Line: while(menu_choice!=0 and menu_choice!=3);voice.speak_wait("ur, where do you think you're going? the zombies haven't had their dayly brain needs met oh well if you really want to go then, good bye.");
Error: Unexpected token 'while'

File: C:\Users\andawn\Documents\random bgt scripts for messing around\test project\Swamp simon.bgt
On line: 64 (47)
Line: while(menu_choice!=0 and menu_choice!=3);voice.speak_wait("ur, where do you think you're going? the zombies haven't had their dayly brain needs met oh well if you really want to go then, good bye.");
Error: Expected identifier

File: C:\Users\andawn\Documents\random bgt scripts for messing around\test project\Swamp simon.bgt
On line: 64 (47)
Line: while(menu_choice!=0 and menu_choice!=3);voice.speak_wait("ur, where do you think you're going? the zombies haven't had their dayly brain needs met oh well if you really want to go then, good bye.");
Error: Instead found '.'

File: C:\Users\andawn\Documents\random bgt scripts for messing around\test project\Swamp simon.bgt
On line: 66 (1)
Line: }
Error: Unexpected token '}'
this time round, I have no idea what's causing the problem though. I cleaned up the code as mcud as I could, looked at examples in help files and the practice game and everything seemed fine to me.

I used to be a knee like you, then I took an adventurer in the arrow.

2015-07-09 10:48:12

Oh no. Declaring a function and calling it are two different things. A function call naturally needs to be done from within an outer function, even if it would be just the main one, but a function declaration just can't be done inside a function, and what you did with the keyboard_practice function is just that. Below is a fixed version of your code.
There may be some typos left, I haven't checked everything character by character, but the basic principle should work like this.
Lukas

#include "dynamic_menu.bgt"
sound music;
sound error;
sound[] tone(4);
int menu_choice;
tts_voice voice;
void main()
{
tone[0].load("1.wav");
tone[1].load("2.wav");
tone[2].load("3.wav");
tone[3].load("4.wav");
error.load("error.wav");
music.load("music.wav");
music.volume=-10;
show_game_window("swamp Memmory");
voice.speak_wait("wellcome to swamp memmory, made from the test game example in the bgt help system.");
music.play_looped();
dynamic_menu menu;
menu.add_item_tts("start getting bashed");
menu.add_item_tts("practice being bashed");
menu.add_item_tts("chicken out");
menu.allow_escape=true;
menu.wrap=true;
do
{
menu_choice=menu.run("here to get hit all over the place? well, this is a very good place to start!", true);
if(menu_choice==1)
{
music.stop();
game_round();
music.play_looped();
}
else if(menu_choice==2)
{
music.stop();
keyboard_practice();
music.play_looped();
}
}
while(menu_choice!=0 and menu_choice!=3);voice.speak_wait("ur, where do you think you're going? the zombies haven't had their dayly brain needs met oh well if you really want to go then, good bye.");
}

void game_round()
{
}

void keyboard_practice()
{
voice.speak_wait("press any of the 4 arrow keys to find out which swamp zombie normal, tyrant, giant or amorphis is attacking you.");
voice.speak_wait("press escape if you are done hitting arrow keys.");
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 t)
{
tone[t].stop();
tone[t].play();
}

I won't be using this account any more or participating in the forum activity through other childish means like creating an alternate account. I've asked for the account to be removed but I'm not sure if that's actually technically possible here. Just writing this for people to know that I won't be replying, posting new topics or checking private messages until the account is potentially removed.