PDA

View Full Version : Tried searching so i'll ask.


Blitzer
01-19-2009, 03:50 PM
Here's my questions:

Alice 2.0

While MyVariable=true
// lots of code that works
if ask user for yes no "try again?"
MyVariable set value = true
// could leave this blank since MyVariable is already true
else
MyVariable set value = false
//while ends here


So basically when the user says "yes" it will loop and when the user says "no" it will cause the while to not run. However when I test it no matter what I choose it will loop back. I know I'm missing something but it's not jumping out at me. Any help is appreciated.


Second I have 2 variables that are storing integers, when it asks the user for input if they enter nothing it goes to null. I do not see a way to stop Alice from outputting a "bug" and stopping it from crashing. I tried setting up an if/else statement to look for <=0 but it will not get that far. Anyone have a solution to null input?

Thanks.

Niteshifter
01-19-2009, 05:14 PM
1. Try putting the while statements in the events area rather than the methods area.

2. Instead of looking for "null", you should try going the other way ie: instead of "if MyVariable == null then...", you should try "if MyVariable != yes or no then..."

DrJim
01-21-2009, 10:13 AM
Also remember that a variable local to a method will reset to the default value after the method runs. This can give problems sometimes.

DrJim
01-21-2009, 11:26 AM
Anyone have a solution to null input?

As far as I can tell there isn't one with just the "ask user for a number" approach - though there are obviously other ways to work the problem (either the yes/no approach or by entering the number as a string). The program just crashes if the user doesn't enter anything in the box.