5.5:Variables
変数
A variable is a place to store data that you create, which
has no on-screen representation.
Variables can hold any data you want to put into them. One
way to think of a variable is as a box with a name on it.
You can put anything you want into the box, and take it out
later, by simply providing the variable's name:
変数は、スクリプトなどで作り出したデータを保存しておく場所で、スクリーンには表示されません。
変数は、そこに入れたいデータならばなんでも保持させることができます。変数を理解する一つの方法は、名前の書かれた箱と考えることです。単純に変数の名前を与えておけば、箱にはなんでも入れることができますし、後になってそこから入れたものをとりだすこともできます。
put
1 into thisThing -- a variable named "thisThing"
put
thisThing into field ID 234
put
"Hello Again!" into line 2 of thisThing
But unlike some other types of container, variables are
non-permanent and aren't saved with the stack. Instead,
variables are automatically deleted either when their
handler is finished running or when you quit the
application (depending on the variable's scope).
You can also use the delete
variable command to delete a variable.
When a variable is deleted, not only the content of the
variable disappears, but also the variable itself--the
"box".
しかし幾つかの他の形式のコンテナとは異なり、変数は永続的に残るものではないため、スタックと一緒に保存はされません。変数は、それを使うハンドラの実行が終了するか、(変数の範囲にもよりますが)アプリケーションが終了された時に、自動的に消去されます。
delete
variableコマンドを変数の消去に使うこともできます。変数が消去されると、変数の内容が消えるだけでなく、変数「box」自体も消えてしまいます。
Tip:
To save a
variable's value, in your application's closeStackRequest
or
shutdown
handler, set a
custom property of the stack to the value of the variable.
To restore the variable, in your application's
startup
or
openStack
handler, put the
custom property into the variable.
秘訣: アプリケーションのcloseStackRequestやshutdownハンドラ内で、変数の値を保存するには、スタックのカスタム・プロパティを変数の値に設定します。アプリケーションのstartupやopenStackハンドラ内で、変数を復元するには、カスタム・プロパティを変数に入れます。