5.5.3:Script
Local Variables
スクリプト・ローカル変数
A script local variable can be used in any
handler in an object's script. You
cannot use a script local variable in handlers in other
objects' scripts. Unlike a local variable, a script local
variable retains its value even after a handler finishes
executing.
To create a script local variable, you must use the
local
command in the
script, but outsie any handler. We recommend you always
declare script local variables at the top of a script so
they are easy to find in one place:
スクリプト・ローカル変数は、オブジェクトのスクリプト内のどのハンドラででも使うことができます。但し、スクリプト・ローカル変数を他のオブジェクトのスクリプト内にあるハンドラで使うことはできません。ローカル変数と違い、スクリプト・ローカル変数はハンドラの実行後は変数内の値を保持することができないのです。
スクリプト・ローカル変数を作るには、スクリプト内でlocalコマンドを使いますが、全てのハンドラの外側で使わなければなりません。(次の例の様に)スクリプト・ローカル変数は常にスクリプトの最上部で宣言するようにしてください。そうすれば、スクリプト・ローカル変数を簡単に確認することができます:
local
mySharedVariable
on
mouseDown
put 2
into mySharedVariable
end
mouseDown
on
mouseUp
answer
mySharedVariable -- displays "2"
(2を表示します)
end
mouseUp
Note:
If you put
the local
command in a
handler, instead of outside any handler, it creates a local
variable instead. The command creates a script local
variable only if you put it in the script but not within a
handler.
注釈: 全てのハンドラの外側でなく、ハンドラ内にlocalコマンドを書き込むと、その変数はローカル変数として扱われます。localコマンドは、あくまでもハンドラないでは無くスクリプト内で使われたときにのみ、スクリプト・ローカル変数を作成します。
Script local variables are automatically deleted when the
application quits or when the script they're declared in
is recompiled.
A script is recompiled when you click Apply in the script
editor, when you close the script editor after changing the
script, and when you use the set
command to change
the script.
スクリプト・ローカル変数は、アプリケーションが終了するか又はスクリプト・ローカル変数が宣言されているスクリプトがコンパイルし直されると、自動的に消滅します。スクリプトがコンパイルし直されるのは、スクリプト・エディタでApplyボタンが押された時や、スクリプトの変更後にスクリプト・エディタを閉じた時、更にはスクリプトの変更にsetコマンドを使ったときです。
You can also use the delete
variable command to delete a script
local variable.
スクリプト・ローカル変数を削除するのに、delete
variableコマンドを使うこともできます。