The easiest way to do this is to use the built-in snapping (or gravity) functions. Since not everyone has the same preferences for these, I would do the following:
1. get the current settings for the user
2. set the default gravity options for your command
3. run your enter function
4. reset the user's settings
;Get user settings
gravity = envGetVal("layout" "gravityOn")
depth = envGetVal("layout" "gravityDepth")
type = envGetVal("layout" "gravityType")
bouncex = envGetVal("layout" "gravityBounceX")
bouncey = envGetVal("layout" "gravityBounceY")
;Set your commands preferences
envSetVal("layout" "gravityOn" 'boolean t)
envSetVal("layout" "gravityDepth" 'int 20)
envSetVal("layout" "gravityType" 'string "edge")
envSetVal("layout" "gravityBounceX" 'float 0)
envSetVal("layout" "gravityBounceY" 'float 0)
;
; Do your stuff here
enterBox ...
;
;Reset to the user's settings
envSetVal("layout" "gravityOn" 'boolean gravity)
envSetVal("layout" "gravityDepth" 'int depth)
envSetVal("layout" "gravityType" 'string type)
envSetVal("layout" "gravityBounceX" 'float bouncex)
envSetVal("layout" "gravityBounceY" 'float bouncey)
If your command errors out, you could end up changing the default gravity settings for the user (since the code doesn't made it to the reset step). To avoid this, you should probably wrap your command with errset to trap the error.
errset(enterBox(...) t)
Derek