MicroWorlds


Programming the keys

You will write two simple procedures to program the keys. In this example the i, m, k, j keys are used to turn and move the turtle while the u and d keys set the pen up or down.

Make sure you have a turtle called t2 on the page.

Type in the following procedures. Create a button with the instruction keycontrol and test your work.

to getchoice
    make "answer readchar
end

to keycontrol
    t2,
   
getchoice
    if :answer = "i [fd 10]
   
if :answer = "m [bk 10]
    if :answer = "k [rt 10]
   
if :answer = "j [lt 10]
   
if :answer = "d [pd]
   
if :answer = "u [pu]
    show :answer
    keycontrol
end

previous | next     A Startup Procedure

 




 



Created by Geoff Adcock
Last Update: 23-Oct-2006