2014-11-08 06:35:01 (edited by Orin 2014-11-08 06:39:40)

Hi all,
In an attempt to fully integrate screen reader support into Memory Train Deluxe, I added a "speech options" item to my main menu which should call the configure() method from Speech Manager. The problem comes up when BGT compiles and it runs into a problem with my while statement for exit game. Since "Exit game" is no longer option 3, but option 4, I changed the statement accordingly to the right int value. Unfortunately it didn't work. The code is below.
menu.add_item_tts("Start Game");
menu.add_item_tts("Keyboard Practice");
menu.add_item_tts("Speech Options");
menu.add_item_tts("Exit Game");

int choice; //This variable stores the players choice for menu options.
do
{

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

speech.speak_wait("Welcome to Memory Train Deluxe!");

choice = menu.run("Use the arrow keys to navigate the menu, enter to activate an option.", true);

if(choice==1)
{
music.stream("sounds/music/" + random(1, 30) + ".ogg");
music.volume=-10;
music.play_looped();
play_round();
}

else if(choice==2)
{
music.stream("sounds/music/" + random(1, 30) + ".ogg");
music.volume=-10;
music.play_looped();
keyboard_practice();
}
}

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

while(choice!=0 and choice != 4);
speech.speak_wait("See ya later!");
}

2014-11-08 07:34:45

Looks like it's an extra brace before the third if statement.

My Blog
Twitter: @ajhicks1992

2014-11-08 08:06:31

Hmm. I just took a look at the language tutorial and found out that ! is the negation operator. I've read it before, I've just forgotten about BGT specifics because I just completed a chapter on logic, and where programming is concerned conditionals, negation etc in a math course. In any case, the BGT compiler says that instead of "Else if(choice==3)", it expects while. But while loop is on the next line.
I'll go take a look at that brace which closes out the second option and see if that's what it is, I hope that's what it is. I guess if you have errors like that BGT really can't determine what it really is, so
it tells you what it thinks needs to be there.
This goes for most intrepreters I suppose. But I'm getting used to it.
Say, Camlorn, I've wanted to program professionally for some time now. You're proficient in three languages and still undergrad, at least from your Twitter profile. Is that by choice, or does your college offer that much coursework in programming? After this math course is done, my college has a Java course that I know of, and I'm thinking about taking that. It wouldn't surprise me if they used Eclipse for their IDE. How accessible is it?
Maybe I might make a new topic to discuss further or hit you up on Twitter, but I haven't networked with anyone--even those that are aspiring programmers, so I need to get on that. big_smile
Thanks.

2014-11-08 19:05:45

Yeah, the second write brace before the third option is definitely the culprit. It's closing the do-while loop that you created, but bgt expects a while statement to be there telling it what condition it should be trying to meet. Instead it sees the third if statement, so it gets mad.

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-09 08:36:00 (edited by camlorn 2014-11-09 08:37:36)

yeah. I'm still undergrad.
As for college, in general, you can do it.  Eclipse is okay but not great.  There's command line everythings for java anyway, so it's not the end of the world--the only part that's questionable is the possible lack of a debugger.  They might also be using Netbeans, which is a bit more problematic, but again-command line.  If you do well, most professors will work with you, at least in my experience-it is sad, but you can and will ride the blindness+doing well=amazing genius whether you want to or not and no matter how much you try not to, especially in a field where half the sighted students will barely figure out hello world before failing.  Computer science isn't only programming, though, which is where the real problems come in: you'd be facing math classes and math classes specifically for computer scientists and we-don't-call-it-math classes if you did it as a degree.  I'm kind of unusual; I found programming in early middle school and find most math is easy once I find accessible materials of one sort or another, so grain of salt and your mileage may vary and all that.
but back on topic: in general, computers do not understand human intent.  In this case, it knows that you started 2 blocks and that you ended two blocks, so obviously it's time for a while.  It can be called many things, but text between {} is what I'm referring to here (other names include compound statement, scope...).  If you mismatch so that there's one or more extra right braces, it'll give an error expecting something or complaining about it.  If it's one or more extra left braces, it usually doesn't show up until the next function definition or the end of the file, at least depending on languages-some languages do inf act let you define functions inside functions, a feature that can be useful but usually is bad practice anyway.
As for what you can do about it, counting comes with practice.  Indentation is a major help and a big deal if you want to program professionally, so try that.  My style guideline for this, at least in those languages that use braces is as follows: left braces on the same line as the thing they open, right braces on a line by themselves, indent by 1 more tab (starting at 0) after every left brace, indent by one less tab after every right brace.  If you then read it with indentation indication on, the mismatches become obvious, though not always glaringly so.  While this code is simple, I don't know anyone who can easily count above 4 levels without some help-more than 4 levels is bad, but it does show up, especially for simple and idiomatic loops over 2-dimensional (or more) arrays.  Some text editors will help you indent, but I've just always done it manually and now it's second nature; such editors frustrate me because I'm already doing it by reflex and then everything goes strange.  NVDA at least will announce on change but also on read line, so it's like having little brace counts before everything that only show up when you ask.

My Blog
Twitter: @ajhicks1992