locked
how to wait until right key is pressed? RRS feed

  • Question

  • My nine year old son wanted to learn programming so he can make some games. I figured this was a great way to start.

    We've been drawing on the screen, laying out text, handling arrays, and all sorts of neat stuff.

    However the simple act of capturing a keypress has us baffled.

    fireKey = "Space"
    quitKey = "Q"
    
    ' The following is our sixth attempt to get intro keys to start the game
    GraphicsWindow.KeyDown = playAgain
    
    Sub playAgain
     LK = GraphicsWindow.Lastkey
     If LK = quitKey then
     Program.End()
     elseif LK = fireKey then
      Init()
    endif
    EndSub

    Our program rights game instructions to the screen. Then it flies right over the above code and into whatever code we put next.

    How do we get it to stop here and wait for one of the desired keys to be pressed? Once the game starts we'll be looking for key events again, including the fireKey, but we haven't programed that far yet.

    Wednesday, June 30, 2010 2:31 AM

Answers

  • You can use while statement:

    WaitingForKey = "True"
    While WaitingForKey = "True"
     LK = GraphicsWindow.Lastkey
     If
    
     LK = quitKey then
    
     Program.End
    ()
     elseif LK = fireKey then Init() WaitingForKey = "False" endif EndWhile

    Sorry My Bad English
    • Marked as answer by wiser3 Thursday, July 1, 2010 2:12 AM
    Wednesday, June 30, 2010 9:36 AM

All replies

  • You can use while statement:

    WaitingForKey = "True"
    While WaitingForKey = "True"
     LK = GraphicsWindow.Lastkey
     If
    
     LK = quitKey then
    
     Program.End
    ()
     elseif LK = fireKey then Init() WaitingForKey = "False" endif EndWhile

    Sorry My Bad English
    • Marked as answer by wiser3 Thursday, July 1, 2010 2:12 AM
    Wednesday, June 30, 2010 9:36 AM
  • Show sample program id KVM584.

     


    Best Regards Martin
    • Proposed as answer by Kroltan Wednesday, June 30, 2010 7:14 PM
    Wednesday, June 30, 2010 10:13 AM
  • check this: WDN534

    i just used a sub and 3 vars to make the turtle move around.


    |"| /"/|"""\ /"""\|"| |__ __| /\ |"""\ |"| | |/ / | " / | | || | | | / \ | |\ \ | | | |\ \ | | \ | | || |__ | | / \ | | \ \| | |_| \_\|_|\_\\___/|____| |_| /_/""\_\|_| \___|
    Wednesday, June 30, 2010 7:13 PM