Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Tried searching so i'll ask.
Old
Blitzer
Guest
 
Status:
Posts: n/a
Default Tried searching so i'll ask. - 01-19-2009, 03:50 PM

Here's my questions:

Alice 2.0
Code:
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.
   
Reply With Quote
Old
Niteshifter
Guest
 
Status:
Posts: n/a
Default 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..."
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 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.
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 01-21-2009, 11:26 AM

Quote:
Originally Posted by Blitzer View Post
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.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2019, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.