To accomplish this we will use the priority colors - you can use the control colors as well.
Step 1: Trace & fill all the objects in your room with a priority color. For immediately adjacent objects, use a different color.
Step 2: Determine the bounding rectangle around each object. This will allow you to re-use a priority color more than once per room. Note that you can have overlapping bounding rectangles for objects - just make sure that the objects have different priority colors. To aid with determining the coordinates of the rectangles, temporarily include the following code in your handleEvent method to give you the cursor hotspot location on a right-click:
(if(== (send pEvent:type) evMOUSEBUTTON and == (send pEvent:modifiers) 515)
FormatPrint("x:%d, y:%d" (send pEvent:x) (send pEvent:y) )
)
EDIT: Even easier, in the picture editor (either Studio or Companion) use the x/y coordinate indicator to get the current location of the mouse.
Step 3: Modify your 'look' logic
(if(Said('look/box')
or
( == (send pEvent:type) evMOUSEBUTTON // mouse click
and == (send pEvent:modifiers) 515 // specifically a right mouse click
and == $0002 OnControl(ocPRIORITY (send pEvent:x) (send pEvent:y)) // on NAVY priority color
// check that the mouse is in the bounding rectangle for this object
and > (send pEvent:x) 93
and < (send pEvent:x) 132
and > (send pEvent:y) 78
and < (send pEvent:y) 110
)
)
Print("The box is closed")
)