Alice Community  

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

Reply
 
Thread Tools Display Modes
Ask user for a 2-digit Number?
Old
JustasM
Guest
 
Status:
Posts: n/a
Question Ask user for a 2-digit Number? - 02-23-2009, 09:49 AM

Attempting to answer jaydenb's question on asking the user for an age, I stumbled across a problem. To ask for a user's age, one should supposedly be able to make a number variable in the world, then, under my first method, set the value to (ask user for a number)[function]. However, apparently, the user can only enter single digit numbers. If you enter a double digit number, the number variable is set to 0.

Why is this? Is a two-digit number not considered a number? And finally, is there a way to ask the user to input a two digit number?

I have attached the world I was working on, to make it more clear. If you press Play, and enter a two digit-number when it asks for your age, it gives the age as 0. Further down, I experimented with using separate variables for each digit, but that is very cumbersome, and doesn't work if you want to work with the entire age value.
Attached Files
File Type: a2w StringTut.a2w (398.2 KB, 21 views)
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 02-23-2009, 11:24 AM

Very strange!

The attached file is a slight modification of the file I posted in response to the original question and seems to work fine. I even added the Eskimo object to make sure there wasn't something strange with it.

The main difference between your posting and the attached is that both the name and age are local variables to MyFirstMethod instead of being defined as world level properties. Local variables are reset to their default value when the method ends while this doesn't occur for world level variables until the world stops.

However, since both events occur at the same time in your program, this shouldn't make a difference. Yet it does for the number - but not the string.

It's probably better to use local variables here anyway - since in general that's better practice - so this is a solution and actually a pretty good one. But why the problem occurs is a mystery to me.
Attached Files
File Type: a2w Name&Age_2.a2w (382.5 KB, 26 views)
   
Reply With Quote
Old
JustasM
Guest
 
Status:
Posts: n/a
Default 02-23-2009, 12:29 PM

Thank you for the reply...

However, I still encounter the same problem, even with the world you posted. Might this be some problem with my version of Alice? (I'm using v2.2 9/1/2008) I've never experienced any major problems with it before. On the other hand, I've never really used strings or have been asking the user anything in my worlds.

The tip about it being better practice to use local variables is also very useful.. I am largely self-taught in Alice, and have not used any book, so my coding is probably not top notch. I've looked a bit at Dick Baldwin's guide, but I thought that I had already nailed most of the basic stuff down...

Thank you all the same.

~~EDIT~~ I have just tried opening your world in Alice 2.0, and it worked smoothly (unlike the application- I'm using Windows Vista). Thus, it must be a problem with v2.2... Maybe I should report it?

Last edited by JustasM; 02-23-2009 at 12:33 PM. Reason: New Info
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 02-23-2009, 04:51 PM

Actually in experimenting a bit more, I found out that my first guess as to the problem was incorrect. (Not unusual, unfortunately. )

If you try to run the attached in ver 2.0 (using Vista), I think you'll find it works OK - at least until you get to the display of the single digits which I have no idea as to how to fix. I really don't think there is a clean way to display a number without the decimal point.

Your first problem seemed to be related to a known bug - namely that when you use the "ask user for a string", the question sometimes repeats. I don't remember the reason but I believe the probem is documented somewhere.

Adding the first wait statement seemed to clear up everything.

Re 2.0 vs. 2.2 - I had the same problem initially in 2.0 so I doubt it's just a version problem. Personally, I don't use 2.2 (it uses too much memory for the improvements you get) so I really can't say for sure.

Re using local variables - Since that relates to encapsulation, which is poorly (if at all) supported in Alice 2.0, I suspect that is the reason Dick didn't include the subject in his tutorials. He has done some good postings in this forum and other places on the subject - I suggest you do a Google search on "Baldwin" and "encapsulation" if you're really interested.
Attached Files
File Type: a2w StringTut-mod.a2w (396.1 KB, 21 views)
   
Reply With Quote
Reply

Tags
number, question, string, user


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 ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.