Search code examples
buttoncanvasracketpause

RACKET pause/continue button for game


I have a school project to create a version of Tetris in racket and I have to implement a pause/continue button which I'm stuck on.. My try:

(define *my-timer*
  (new timer%
       [notify-callback (lambda () (send *my-game-canvas* refresh))]))

(define *pause*
  (new button%
       [parent *my-window*]
       [label "Pause"]
       [callback (lambda ()
                   (send *my-timer* stop))]))

At the moment only the pause function is implemented but it doesn't work. I get an error message on the second define.

*my-game-canvas * is the canvas there the game graphics take place.

I appreciate all the answers.

/ Kasper

Edit:

The error I get:

initialization for button%: contract violation
  expected: (procedure-arity-includes/c 2)
  given: #<procedure:...0160511/game.rkt:61:17>

Solution

  • The problem is this clause:

       [callback (lambda ()
                   (send *my-timer* stop))]
    

    A callback needs to take two arguments: the button and the event.

    Try this:

       [callback (lambda (button event)
                   (send *my-timer* stop))]