hilaloytun
2022-7-23 16:58:26

Hello, I have a problem with world functions. If I don’t touch keypad or mouse it stops when image reaches at the right edge of the scene, but If I click mouse or press a key, it never stops. (define (main ws) (big-bang ws [on-tick tock] [to-draw render] [stop-when gone] ;; This doesn’t work if I press a key or click with mouse !!! [on-mouse mouse-event-handler] [on-key handle-key] ))


soegaard2
2022-7-23 16:59:05

How is gone defined?


hilaloytun
2022-7-23 16:59:43

it should stop when image mostly disappeared from the scene: (define (gone cw) (= cw (+ BACKGROUND-W 23)))


soegaard2
2022-7-23 17:00:28

Try (define (gone cw) (>= cw (+ BACKGROUND-W 23)))


hilaloytun
2022-7-23 17:01:32

it worked perfect. Thanks.


hilaloytun
2022-7-23 17:04:08

But If I may ask; why it works? I mean it would be true in either cases, because x position of the image will eventually be equal to that specific number at some point?


soegaard2
2022-7-23 17:09:11

Well, as it turned out cw never did equal (+ BACKGROUND-W 23)). To check you need a way to see the value of cw during the run of the program. One way is to change your render methods to do this:

(overlay (text (number->string cw)) ...what you have now in render...) This way you can follow the value of cw as the program runs.


hilaloytun
2022-7-23 17:13:57

Thank you very much, ok I’ll try it.


hilaloytun
2022-7-23 17:21:11

Ah ok, now I understand why they won’t be equal. Because tick and the image pixels won’t overlap, when I intervene with a key or the mouse. Thanks again.