Difference between revisions of "状態"

From Second Life Wiki
Jump to navigation Jump to search
m (New page: {{Multi-lang}} {{LSL Header/ja}} <div style="float:right">__TOC__</div> In LSL, most scripts sit idle until they receive some input, or detect some change in their environment. At any mome...)
 
m
Line 2: Line 2:
{{LSL Header/ja}}
{{LSL Header/ja}}
<div style="float:right">__TOC__</div>
<div style="float:right">__TOC__</div>
In LSL, most scripts sit idle until they receive some input, or detect some change in their environment. At any moment, the script is in some state, and will react to events or inputs according to some scheme defined by the programmer. However, a script can also contain two or more different states, and react differently to events or inputs depending on what state it is in.
LSLでは, ほとんどのスクリプトは何らかの入力を受け取るか、環境における何らかの変化を検出するまで何もしていない. どの瞬間も, スクリプトは何らかの状態(state)にあり, プログラマーによって定義された仕組みにしたがってイベントや入力に反応しようとする. しかし, スクリプトは二つ以上の状態をもつことができ, どの状態にいるかにより, イベントや入力に対して異なった反応をする.


The main state is the default state. When a script is compiled, reset or loaded, this is the state it enters by default. After the default state definition can follow additional state definitions which the script may use to change how and which events are handled.
主たる状態はdefault状態である. When a script is compiled, reset or loaded, this is the state it enters by default. After the default state definition can follow additional state definitions which the script may use to change how and which events are handled.
{{#vardefine:name|state
{{#vardefine:name|state
}}{{#vardefine:p_jump_state_desc|name of a state to run
}}{{#vardefine:p_jump_state_desc|name of a state to run

Revision as of 02:42, 12 December 2007

LSLでは, ほとんどのスクリプトは何らかの入力を受け取るか、環境における何らかの変化を検出するまで何もしていない. どの瞬間も, スクリプトは何らかの状態(state)にあり, プログラマーによって定義された仕組みにしたがってイベントや入力に反応しようとする. しかし, スクリプトは二つ以上の状態をもつことができ, どの状態にいるかにより, イベントや入力に対して異なった反応をする.

主たる状態はdefault状態である. When a script is compiled, reset or loaded, this is the state it enters by default. After the default state definition can follow additional state definitions which the script may use to change how and which events are handled.

default { events }

default { events }
• event events one or more events

The default state definition.

state target { events }

• label target state name
• event events one or more events

target state definition.

|- |

state target;

• label target name of a state to run

When a state target; is encountered at runtime, if the current state and the target state are different:

  1. Trigger state_exit in the current state if it exists and clear the event queue.
  2. Change state to target, any listens are unregistered.
  3. Trigger state_entry in the target state if it exists.

If target state is the same as the current state, no state change occurs nor do any of the side effects.

Caveats

  • On state change:
    • All listens are released.
    • The event queue is cleared
  • The default state must be defined before all others.
  • States cannot have user functions or variables inside their immediate scope, only event definitions may be inside a states scope.

Examples

default
{
    touch_start(integer a)
    {
        state hello;
    }
}

state hello
{
    state_entry()
    {
        llOwnerSay("Hello");
        state default;
    }
    state_exit()
    {
        llOwnerSay("Goodbye");
    }
}

See Also

Keywords

•  jump
•  return

Events

•  state_entry
•  state_exit