touch_start


touch_start(integer num_detected)

エージェントがスクリプトが入ったオブジェクトに最初に触れたとき、このイベントが発生します。
タッチするエージェントの数はnum_detected引数を通じてスクリプトに伝わります。
それらのオブジェクトに関する情報はllDetected*機能で集められるかもしれません。


イベント 引き金となるアクション 複数回の検出
touch() エージェントがオブジェクトをクリックしてる間 YES
touch_start() エージェントがオブジェクトをクリックし始めた時 NO
touch_end() エージェントがオブジェクトをクリックをやめた時 NO



注意:
「タッチ」とは「クリック」を意味していて「接触(衝突)」ではありません。
衝突に対処するには、collision(),collision_start(),collision_end()イベントを使用してください。
touch()touch_start()あるいはtouch_end()のイベントを含んでいるスクリプトは、それらがそれをクリックすることを意味する場合にオブジェクトをドラッグするユーザによって引き起こされた「プリムドリフト」を受け付けるかもしれません。
これを回避するためには、グラブを防止するためにllSetStatus(STATUS_BLOCK_GRAB、TRUE)を使用するか、以下を見てください。
マウスボタンが下がっている間に、スクリプトがステートを変更し新しいステートが3つタッチイベントのうちのどのイベントハンドラーも持たない場合、この種のドリフトが起こります。
また、これらのステートに何もしないハンドラ(つまり空白のハンドラ)を加えると、ユーザがオブジェクトのドラッグ操作を許容している間、問題は避けられます。
上のテーブルの「いいえ」は不正確です。シングルマウスクリックで あなたのスクリプトは複数のtouch_startイベントかtouch_endイベントを得ることができます。
不思議なことに!この問題はいくつかのマウスで起こりますが、他のものでは起きないものもあり、、たぶんマウスドライバーに関係しています。
touch_start()イベントでステーツの変更を要求すると、新しいステーツはアクティブになったときに、まだあなたの指がマウスボタン上にあれば、新しい状態のtouch_start()のイベントを引き起こしてしまいます。
ステーツ変更を引き起こすためにtouch_end()イベント使用することにより、これを回避してください。


llSetTouchText()関数、llPassTouches()関数も参照してください。


Q: I see a lot of llDetected*(0), which seems like hacky laziness since even though this is a singular event and so unlikely to coincide, it seems possible for two touch starts to be described in a single event. Does it work that way?
A: Yes, multiple touches can be combined into a single event, but since this is rare you can get away with just checking index 0. When you suspect things get clicked a lot and close together, such as perhaps in competitive games, you should use a for or while loop to step though all the avatar references.
Q: Why you can't touch objects attached to somebody else?
A: As of 1.12 you can
Q: how to code so only the touchable object's owner can touch it?
A: Use a For loop and compare llDetectedKey to llGetOwner
Q: How the owner can script the touchable object to only allow specific people to touch it?
A: Use a For loop and use llDetectedName to compare to a list of names using llListFindList
Q: How to prevent inappropriate invisible touchable objects in PG sims?
A: Use llRequestSimulatorData.

You can also time how long the touch went for with this quick hack:
float time = 0.1;
default
{
   touch_start(integer num_detected)
   {
       llSetTimerEvent(0.1);
   }
   [[timer]]()
   {
       time = time + 0.1;
   }
   touch_end(integer num_detected)
   {
       llSetTimerEvent(0.0);
       llInstantMessage(llDetectedKey(0),
                        llDetectedName(0) +
       " you held down your mouse button for " +
        (string)time + " seconds.");
       time  = 0.0;
   }
}
最終更新:2008年10月01日 10:01