Could anyone give some hints (or a full solution!) to how to convert the model library code example 'Mouse Drag Multiple Example' to a non wrapping world. My attempts destroy the selection rectangle (the sides of the rectangle pile up at the edge - because each part is treated separately). Similarly the selected turtles just pile up at the edge. Thank you.
Here's the main procedure from the model - it gives a runtime error on the second setxy when the side of the selection rectangle gets to the edge of the non-wrapping world:
to handle-drag
;; remember where the mouse pointer was located when
;; the user pressed the mouse button
let old-x mouse-xcor
let old-y mouse-ycor
if selected? old-x old-y [ ;; selected? is a reporter defined below
while [mouse-down?] [
let new-x mouse-xcor
let new-y mouse-ycor
;; we need to move both the selected turtles and the sides
;; of the selection rectangle by the same amount that the
;; mouse has moved. we do this by subtracting the current
;; mouse coordinates from the previous mouse coordinates
;; and adding the results to the coordinates of the turtles
;; and sides.
ask selected
[ setxy xcor + new-x - old-x
ycor + new-y - old-y ]
ask sides
[ setxy xcor + new-x - old-x
ycor + new-y - old-y ]
set old-x new-x
set old-y new-y
;; update the view, otherwise the user can't see
;; what's going on
display
]
]
end
This is completely untested. It sounds like what you need is to pretest the potential position to make sure if doesn't go past the edge of the world and, if it does, reduce the amount of movement accordingly.
Try amending this section:
with:
You will need to add in the sides (this only does selected) and do similar for y coordinates.