arrowKey Code

Here is the final code: You can use (copy and paste it) in the rest of the lessons. (After you paste it, press the tab key to make it more readable)

Change it as follows:

    The code goes on the card or the stack.

    The object being moved in this code is - button "box".  Change it to your object and it's name

    The card is called "my card". Change it to the name of your card.

--------------------------------------------------- FINAL CODE ----- COPY THIS AND PASTE IT INTO YOUR PROGRAM ---------------------------------

on arrowkey x

if x is "up" then
  set the top of button "box" to the top of button "box" - 10
  if top of button "box" < 0 then
    set the top of button "box" to 0
  end if
end if

if x is "down" then
  set the bottom of button "box" to the bottom of button "box" + 10
  if the bottom of button "box" > the bottom of card "mycard" then
    set the bottom of button "box" to the bottom of card "mycard"
  end if
end if

if x is "left" then
  set the left of button "box" to the left of button "box" - 10
  if the left of button "box" < 0 then
    set the left of button "box" to 0
  end if
end if

if x is "right" then
  set the right of button "box" to the right of button "box" + 10
  if right of button "box" > the right of card "mycard" then
    set the right of button "box" to the right of card "mycard"
  end if
end if

end arrowKey

--------------------------------------------------- FINAL CODE --------

Comments