Return/ja

From Second Life Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The correct title of this article is return/ja. The initial letter is shown capitalized due to technical restrictions.

return value;

return value;
• type value 関数による値もしくは変数が返され、関数によって返される型とあわせなければなりません。

値が一つだけ実行する前の範囲に返して使用されます。

関数

関数が終了すると、呼び出したポイントに戻ってスクリプトが継続します。

イベント

スクリプトがクラッシュします。イベントは値を返すことができません。 このキーワードの代わりに次の方法を使いましょう。

return;

関数やイベントが最後まで完了するよりも早くreturnを実行する場合に使われます。 イベントや関数を最後まで行う、とコンパイラによって見込ませたい場合は使うべきではありません。

関数

関数が終了すると、呼び出したポイントに戻ってスクリプトが継続します。

イベント

イベントが終了すると、イベントのキューから除去されます。もしほかのイベントキューが存在するなら、そのイベントが実行されます。

注意点

  • コンパイラにバグがあり、値とイベントを変えそうとする場合、ランタイムはスクリプトのクラッシュに遭遇するでしょう。

サンプル

integer Goodbye()
{
    llOwnerSay("Goodbye");
    return 0;
}

Hello()
{
    llOwnerSay("Hello");
    return;
}
string get_name(key uuid)
{
    return llKey2Name(uuid); // Returns the value of llKey2Name().
}

// Usage within the script:

llOwnerSay("Name: " + get_name( llDetectedKey(0) ) ); // Tell owner what the name is.


integer Calc (string cmd, integer a, integer b)
{
    // The user function has been declared as returning an integer,
    // so every return within the function must return an integer
    if (cmd == "+")    return a + b;
    // We don't need to code 'else' here, as the preceding statement resulted in 'return' when true
    if (cmd == "-")    return a - b;
    if (cmd == "*")    return a * b;
    if (cmd == "/")    return a / b;
    // We must return a value here too, we can't omit the final return
    return -1;   
}
default
{
    state_entry()
    {
        llSay(0, llList2CSV ( [ Calc("+",1,2), Calc ("-",5,3), Calc ("*",3,4), Calc("/",18,6) ] ) );
    }
}

参考情報

キーワード

•  jump
•  state