Dear All,

I am not sure if this is the right place since I am working from the Realm of 
Racket book. If not, please let me know where I can take my question. I 
finished up chapter five, and wanted to modify the UFO example to move in 
relation to the arrow keys. Here is the code that I wrote:

#lang racket
(require 2htdp/universe 2htdp/image)
 
(define WIDTH 600)
(define HEIGHT 600)
;;The image won't copy and paste, but you get the idea.
(define IMAGE-of-ufo .)
 
(struct ufo (xpos ypos))
 
(define (move-up w)
  (add1 (ufo-xpos w)))
 
(define (move-down w)
  (sub1 (ufo-xpos w)))
 
(define (move-right w)
  (add1 (ufo-ypos w)))
 
(define (move-left w)
  (sub1 (ufo-ypos w)))
 
(define (render-ufo w)
  (place-image
   (scale 0.25 IMAGE-of-ufo) (ufo-xpos w) (ufo-ypos w)
   (empty-scene WIDTH HEIGHT)))
 
(define (move-UFO w key)
  (cond [(key=? key "up") (move-up w)]
        [(key=? key "down") (move-down w)]
        [(key=? key "left") (move-left w)]
        [(key=? key "right") (move-right w)]
        [else w]))
 
(big-bang (ufo 70 60)
          (on-key move-UFO)
          (to-draw render-ufo))

When I click the Run button, the output initially looks good. However, when I 
press an arrow key, I get an error. Attached is a screenshot with what I see in 
the definitions pane.

The error message in the interactions pane is:

"ufo-xpos: contract violation
  expected: ufo?
  given: 61"

I do not get why the contract is broken. The function place-image takes an 
image, number, number, and a scene. What mistake am I making? Thanks in advance.

Patrick

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to