From: Siep Korteling Date: 2008-07-28T08:26:46+09:00 Subject: Re: deaf grandma. houston barnett-gearhart wrote: > thank you, martin, for your reply. i took your advice & wrote an > algorithm & it's been helping me along quite well. but, i've a few > questions that arose while i was writing the program. before i get > started, here's the program thus far: http://pastie.org/242167. i > realize that the code is a mess & i probably did much more than was > necessary, but like i said, i'm fairly new to ruby, let alone > programming. by all means, please suggest how i could clean it up a bit. > now, for my questions. foremost, after grandma's spiel about it being so > long since she last saw you & how mother said you had a question for > her, if you ask the question & you capitalize any letter in your > question, the program ends. why is that? second, visually, when the > program is running, it's not particularly fun to look at. i figured > centering the text would make a bit more pleasing to the eye, but not so > much. is there a string method that enables you to output whatever > grandma is saying as if she is typing it in real time? if so, how can i > implement that in my program? > > that's the gist of my questionnaire. it's been frustrating, but as i > figure things out by myself or through the hints people give me, i get a > feeling of accomplishment. i understand that i'm just starting out & i > shouldn't expect to have an elite knack to code in ruby, but i've been > at this program on & off for 2 days & i'm not really getting all the > results i've wanted. there's still a lot i need to work in. > specifically, grandma's response if you give her initial question an > answer that is not "yes," "Yes," "no," or "No," on top of the extension > to the program, which is a whole other monster for the time being. > > again, any help is appreciated. Well. you have a whole lot of "if" statements. An if statement has a something which is true or false; in your case reply1 == "yes" If it's true, the code behind it will run. If it's false, the code after an else-statement will run. If there is no "else" , the if statement will ignore all code until it finds it's "end" statement. In your case that means all following code is skipped. The "end"s are misplaced. You might want to look into "while" or "until" to tackle this. childs_reply = "" until childs_reply == "BYE" childs_reply = gets.chomp ##do smart stuff #if #else #end end Regarding grandma's typing. She's going to do this all the time, so let's make a method. Basically we want to recieve a string, take each letter, print it and then pause a little. def grandma_says(str) #str is the stuff we're going to show. str.each_byte do |byte| #Whoa. each_byte? Never mind, it's there to print byte.chr #handle non-western character sets. sleep 0.1 STDOUT.flush #major pain in the ass, this (on windows). end puts #forces a line ending when grandma is finished. STDOUT.flush end grandma_says("I may be old but I'm not slow!") Hth, Siep -- Posted via http://www.ruby-forum.com/.