Re: Live Tutoria?
- Posted by Jason Gade <jaygade at yahoo.com> Jan 21, 2006
- 493 views
Lynn Kilroy wrote: > > >Okay, the line in your program > >while Key != 27 do > >is the problem. Before that, you have declared Key but not yet assigned it= > > >a value. All variables must be assigned a value before they are compared o= > r > >added 1 to or whatever. > > > >So before your loop you must say > >Key = 0 > >or > >Key = Inkey() > > > >So here is your code (untested, but should work) > > > >}}} <eucode> > >include ..\..\include\Inkey.e > > > >integer Key > >Key = 0 -- could put this on the same line if you wanted to, like this: > >-- integer Key Key = 0 > > > > > >Prekey() > > > > > >while Key != 27 do > > > >Key = Inkey() > > > >? Inkey() > > > >end while > ></eucode> {{{ > > > >Instead of assigning 0 to Key, you could put an initial condition right= > > >before your loop, as follows: > > > >}}} <eucode> > >Key = Inkey() -- initial status of variable > >while Key != 27 do > > > >Key = Inkey() > > > >? Inkey() > > > >end while > ></eucode> {{{ > > Thank you! I reformatted the query and reposted it. But since you've > answered the question, I guess we can just ignore the other one. {Giggles}= > > Or I'm more likely to get more and more replies. {Laughs} > > So it is a pretty simple concept. > > 1. Declare the variable. > 2. Assign the variable a value. > 3. Use the variable. > > That's a little different from QB. In QB, you define it and it had an > default assigned value. I will remember that. > > I will not put a second statement on the same line, and all my > initialization code will always be placed before the first sub {procedure}= > > or function call. {Smiles} The program returned nothing but -1's all the wa= > y > up the screen. That's a start. > > With this information, I cleared up the bug, and I added Waitkey. This > completes the Inkey.e Include file. Here is the final program to this > point. > > Begin Learning.Ex > =========== > include ..\..\include\Inkey.e > > integer Key > > Key = 0 > > Prekey() > > while Key != 27 do > > Key = Waitkey() > > ? Key > > end while > ========== > End Learning.Ex > > Begin Inkey.e > ========== > global function Inkey() > return get_key() > end function > > global procedure Prekey() > while Inkey() > -1 do > end while > end procedure > > global function Waitkey() > > integer Key > > Key = -1 > > while Key = -1 do > Key = Inkey() > end while > > return Key > > end function <snip> Try this (tested code):
include get.e include graphics.e procedure ColorLocatePrintTextOnly(integer FGC, integer BGC, integer Row, integer Col, sequence Text) text_color(FGC) bk_color(BGC) position(Row, Col) puts(1, Text) text_color(WHITE) bk_color(BLACK) end procedure object Key clear_screen() ColorLocatePrintTextOnly(RED, BROWN, 12, 34, "Hello, World!") Key = wait_key()
Let me know if you have any more questions. Oh, I don't know if you are using email or the web interface for EUforum. If you are using the web interface, you can put \<eucode\> \</eucode\> around a code snippet to "colorize" it in the forum. I don't know if that will come out right (we need a preview in the webforum, please!) but if not, here it is in english: (less-than-symbol)eucode(greater-than-symbol) --code-- (less-than-symbol)/eucode(greater-than-symbol) -- "The author regrets that he is unable to reconcile himself to the thoughtful point of view you have expressed. However, it must be kept in mind that being raised in different cultures and different places can result in such differences of viewpoint between individuals. The author is from planet Earth." [author unknown] j.