touch(integer num_detected)
This
event is repeatedly triggered
while a
user (
agent) is clicking on ("touching") the
object containing the script.
The total number of touching agents is passed to the script in the
num_detected parameter. Information on those agents may be gathered via the
llDetected* functions.
Lag/Performance Advisory:
Be aware that the
touch_start() event is recommended for virtually all cases where you need to touch an object. The only time you should be using
touch() is when you actually need the object to be receiving touch updates several times a second. Additionally, a bug has recently been discovered that causes the
touch() event to continue reporting
touches after the object has stopped being touched. There is no word yet on a fix. For both these reasons,
touch_start() is recommended over
touch(), unless absolutely necessary.
Event: | Triggered: | Triggered multiple times: |
touch() | while a user is clicking on the object. | YES |
touch_start() | when a user starts clicking on the object. | NO |
touch_end() | when a user stops clicking on the object. | NO |
Notes:
- "Touch" means "click on", not "collide with"; to deal with collisions, use the collision, collision_start, and collision_end events.
- Scripts containing a touch, touch_start, or touch_end event may be subject to "prim drift" caused by the user dragging the object when they mean to click it. To avoid this, use llSetStatus(STATUS_BLOCK_GRAB, TRUE) to block grabs, or see below.
- This kind of drift happens if the script changes state while the mouse button is down and the new state does not have any of the 3 touch event handlers. Adding a handler that does nothing to these states also avoids the problem, while still allowing the user to control-drag the object.
- The "NO" in the table above is inaccurate. Your script can get multiple touch_start or touch_end events on a single mouse click. Go figure! This happens with some mice but not others, and is probably mouse driver related.
See also the
llSetTouchText and
llPassTouches functions.
Events