[Home] [Back to Message Index]

Global SchoolNet - Automated Message Archive

Re: LOGO-L> MWorlds ?@ keys




Augusto Chioccariello (augusto@itd.ge.cnr.it)
Fri, 17 Jan 1997 18:08:20 +0100

>One of my sixth graders is using Microworlds and is trying to program a
>soccer game. One of the things he wants to do is have the arror keys or the
>number keys on the keyboard have spacific functions for his game. Like
>turning and moving the players. I am more familiar with Logo Plus. With it
>we could say:
>
>Make "key rq
>if :key = char 56 then fd 10

Dear Debra,
to listen for keyboard input in MW you need to use "readchar", which
returns a character (look for the description of readchar in the on line
help for further info). To chek for any keys, even non printable ones like
the arrow keys, you need to use the ASCII code. In MW you could say:

make "key readchar
if (ascii :key) = 56 [fd 10]

To discover the ascii codes associated to various keys you could use the
following instruction in the command center:

show ascii readchar

As for the game you want to start a separate proces that does the following:

If a key has been pressed
then check if there is an action associated to that key
then execute the action

In MW you could say:

to keyboard-input
forever [if key? [process-key]]
end

to process-key
let [key ascii readchar]
if :key = 30 [fd 10 stop] ; up arrow key on the Mac
if :key = 31 [bk 10 stop] ; down arrow key on the Mac
end

If you have 2 turtles (t1 and t2) you can assign action to each turtle as
follows:

to process-key
let [key ascii readchar]
if :key = 30 [t1, fd 10 stop] ; t1 goes forward
if :key = 31 [t2, bk 10 stop] ; t2 goes back
end

In MW version 2 you might use "when" instead of "forever" to start a
separate process:

when [key?] [process-key]

(Check: key?, forever, when and let in the on-line help for more info)

I hope this helps.

Cheers,
Augusto

PS I do like Michael sample, it just shows that he's used to deal with kids
more than I do.

/// Augusto Chioccariello
/// Istituto Tecnologie Didattiche - CNR tel. +39 10 6475319
/// email: augusto@itd.ge.cnr.it fax +39 10 6475300

---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org. Mail
questions about the list administration to logofdn@gsn.org. To
unsubscribe send unsubscribe logo-l to majordomo@gsn.org.