From Second Life Wiki
Listen
llListen
nameとidからchannel上にmsgのコールバックが設定されます。
listenを無効か除去可能のinteger値を返します。
| • integer
| channel
| –
| any valid integer, positive or negative.
|
|
| • string
| name
|
|
|
|
| • key
| id
|
|
|
|
| • string
| msg
|
|
|
|
msg、nameかidが空の場合は、入ってくるメッセージはフィルタにかかりません。
idが無効か、null keyの場合、空とみなされます。
仕様
listenイベントが作動されるため、主要に判定する基準をフィルタで強く設定すべきです。すべての基準はlistenイベントが生成したものを一致させつづけるだけです。最初に、メッセージはチャンネルchannel上で伝送されつづけます。nameが設定されている場合、話し手の名前をnameと正確に一致すべきです。idが有効な場合、nullではないkeyは話し手のkeyと同等にすべきです。msgが設定されている場合、話し手のメッセージとmsgを正確に一致すべきです。
警告
- ステート変更あるいはスクリプトリセットで、すべてのlistenは自動で除去されます。
- ステート変更はlistenの開放のショートカットのように使えます。
- 65listenまでが何らかの単独スクリプトで同時に開くことができます。
- この数を超えた場合、Script run-time errorとToo Many Listensエラーを引き起こします。
- マイナス域のチャットナンバーでチャットは、クライアントのダイアログボックスを除いて出力することはできません。
- これはオブジェクト同士のコミュニケーションの典型的なつくりです。
- これはクライアント上に置かれた人為的な限度かもしれず、プロトコルによるものではありません。
例
オブジェクトオーナからの何らかのチャットを聞き、一度だけ返答する、些細な例です。ラグの削減と周囲のユーザのスパムを回避するため、0以外の広範囲チャンネルから選んでlistenすることと、'/5 hello'のような、選択チャンネル上でのチャットによるlistenイベントで作動することです。
// says beep to owner the first time owner says something in main chat;
integer listen_handle;
default
{
state_entry()
{ //Registers the listen to the owner of the object at the moment of the call.
// This does not automatically update when the owner changes.
// Change 0 to another positive number to listen for '/5 hello' style of chat.
listen_handle = llListen(0, "", llGetOwner(), "");
}
listen( integer channel, string name, key id, string message )
{
llOwnerSay("beep");
// Stop listening until script is reset
llListenRemove(listen_handle);
}
on_rez(integer param)
{ //Triggered when the object is rezed, like after the object had been sold from a vendor
llResetScript();//By resetting the script on rez it forces the listen to re-register.
}
changed(integer mask)
{ //Triggered when the object containing this script changes owner.
if(mask & CHANGED_OWNER)
{
llResetScript();
}
}
}
ノート
チャンネル0は避けて、避ける可能性のあるnameやidを設定します(Lag)。llListen(0,"","","")はチャット範囲の皆からのチャットを聞くため確実にラグとなりやすく、それらのコストは回避すべきです。