2014-11-16 00:29:38 (edited by Orin 2014-11-16 00:39:56)

Hi all,
So in this other project I have, I've got a menu with music working as well as having the speech manager class up and running.
I also again got unexpected end of file, but I have less code with this so it's easier to work with as there's a total of about four braces.
The idea is to create a do loop in the menu that checks to see if one of the choices in the menu is selected, where it will then call the functions. Game i don't have coded yet but I'll start as soon as I get this sorted, speech options should call configuration from speech manager, and exit calls exit to exit the game of course. This time I'm breaking up all my functions into includes, I just can't deal with five-10 functions, all dealing with different things in one file. I'm talking about functions that branch off into different things entirely. This time I'll make an object for player interaction and another for enemies--I also did try to make an effort to indent this time, especially with the do loop since there's lots of braces in it but not as much as I have to keep track of in the Memory Train Deluxe file. How do I turn on mismatching indents in NVDA? People were talking about but I have never scene it.

The way I understand these closing braces is that the first right brace closes the if statement for choice four exit, the second one closes the do loop, and the third closes the main function.
Thanks for your help all. Code:

#include "dynamic_menu.bgt"
#include "speech_manager.bgt"
//The main menu, speech and other things.
speech_manager speech;
sound music;
void main()

{

speech.init("Config.dat", "9223315");

music.stream("sounds/music/mainmenu.ogg");
music.volume = -10;

show_game_window("Test");
dynamic_menu menu;
set_error_output("error.log");
music.play_looped();
int result;
menu.set_speech_mode(speech.mode);
menu.set_tts_object(speech.sapi);
menu.add_item_tts("start");
menu.add_item_tts("Speech Options");
menu.add_item_tts("exit");

int choice;

result=menu.run("Please choose an option.", true);
do
{    if(choice==1)
{
game();

}

    else if(choice==2)
{    speech.configure();
}
else if(choice==3)
{    exit();

}
}
}

edit: So I put this particular file through the BGT matcher, and it says I have 22 quotes which I suppose should be normal for the parameters of functions require them around quotes, but 0 unclosed braces and 0 unclosed brackets. This tells me that it's not a braces error but something logical or syntax related? That's good to know as it's only my second do loop.

2014-11-16 03:47:08

You never actually gave a condition for the loop to keep running. It would go just before the final right brace in your code. The condition looks liek
while(condition);
basically the do loop will continue running while that condition evaluates to true, and the condition is checked after every execution of the loop. This means the loop will run at least 1 time.
development hint: This is not a prolem in the code, but you may want to remove the if statement for option 3 and make that your while condition. This would make the program continue execution past the menu loop if option 3 was selected. Since there is, currently, nothing beyond the do while loop except the end of the main function, that should, in effect, quit your game.

I like to sleep, Sleep is good,
This is how I do it: Lie on a nice warm cozy bed, and dream dreams about how to rule the world!
Follow @TheGreatAthlon5 on twitter for humorous facts and game updates!
If you like my posts, thumb me up!

2014-11-16 04:12:53

NVDA will not tell you about mismatches.  NVDA will announce changes in indentation.  The trick is that you always know what level you're at, not that you suddenly get an auto-matcher out of it.  If the level isn't back to 0 at the end of a function, for example, then you've missed a brace.  If the level goes to 0 before the end of a function, then you've got an extra.  Doing it will eventually become first nature, which is better than second nature until you realize you can't turn it off even though your editor has decided to "help" you (not likely to be an issue for a BGT programmer).  It's in the formatting dialog.
Since I toggle it so often, nvda+n, p, f, i, space, enter.
As for your code, it's the second-to-last brace.  The syntax of do is:
do {
statements...
} while(condition);
It is worth noting that if that code was indented, it was lost when you brought it to the forum.
Since BGT is not a big deal like C++ and Python, I can't give you specific best practices for style.   But coming up with style rules is important, and I suggest following them religiously.  You may eventually wish to switch to what is known as "one true brace", that is:

do {
} while(condition);
if(condition) {
}
else {
}
while(condition) {
}

But this doesn't matter so much for languages where the community isn't large enough to have a default that spans 20 years, and your current style certainly makes checking to make sure you actually put them in easier.  The advantage to one true brace, as far as I'm concerned, is that it's simply less to arrow through.  I'm not criticizing, just providing something you might want to be aware of.  It's common in C/C++/Java.
And finally, there's always the find comments.  They don't really have an official name.  Basically it's leaving comments in that are easy to find for--for example, //todo: or, in the case of Libaudioverse, //begin public API.  This is extremely helpful in really big files.  You can split things up, but not always.  500 line files are common in the real world.  My biggest is, ironically, almost exactly 666 lines.  Anything bigger than that may be too much.  The worst I've seen is a 10000-line single-file library for playing audio that included code for 3 platforms in the same file and, ironically but not surprisingly, failed to work right.  If you're wondering about navigation, it comes down to learning find/replace and, if you can, getting an editor with find by regular expression for those times when nothing else will do.  This is one thing that C++ makes ironically easier: if you're blind, the header file makes a great table of contents for the much larger source files.

My Blog
Twitter: @ajhicks1992

2014-11-16 05:23:02 (edited by stewie 2014-11-16 05:27:42)

Also.

when you run the do loop, you don't actually call the menu for each loop iteration. so if you chose a result say 0 or -1 after hitting escape, that do loop would execute forever and bog down your system.

Deep in the human unconscious is a pervasive need for a logical universe that makes sense. But the real universe is always one step beyond logic.