VariablesWML
用途 (Purpose)
Variables are used to record information for later use.
変数は、後で使うために情報の記録をするのに使われます。
変数は、後で使うために情報の記録をするのに使われます。
For instance, assume that a choice a player makes in one scenario should affect a later scenario. With a variable, that choice can be recorded, and made available to the later scenario.
例えば、シナリオ内でプレイヤーが選択したことが、後のシナリオに影響を及ぼすとします。変数はその選択を記録し、後のシナリオで使用できるようにします。
例えば、シナリオ内でプレイヤーが選択したことが、後のシナリオに影響を及ぼすとします。変数はその選択を記録し、後のシナリオで使用できるようにします。
概説 (Overview)
Each variable is given a name. A given variable name may contain only alphabetic characters, digits, and underscores.
それぞれの変数には名前が与えられます。変数名に使える文字は、[a-zA-Z0-9_](アルファベット, 数字, アンダースコア)です。
それぞれの変数には名前が与えられます。変数名に使える文字は、[a-zA-Z0-9_](アルファベット, 数字, アンダースコア)です。
A variable can be assigned, queried, and cleared.
変数は、代入、問い合わせ(query)、そして削除ができます。
変数は、代入、問い合わせ(query)、そして削除ができます。
- Assigning a value to a variable (usually with [set_variable]) stores that value in the variable. Every variable can be assigned an initial value at the beginning of a scenario by using the [variables] tag.
- 変数への値の代入(通常 [set_variable] を使用)は変数へその値を格納します。すべての変数は [variables] タグを使うことでシナリオの始めに初期値を設定できます。
- Querying a variable returns the last value stored in it (or the empty string, if no value was).
- 変数への問い合わせでは、変数に最後に格納された値が返されます。(値がない場合は、空文字列を返します。)
- Clearing a variable makes Wesnoth forget about that variable. This is useful since Wesnoth must save all used variables when a game is saved. A variable can be cleared using [clear_variable].
- 変数のクリアをすると、Wesnothにその変数を忘れさせます。ゲームが保存されたとき、Wesnothはすべての使用された変数を保存する必要があるため、これは役立ちます。
In these operations, a variable is identified by its full name.
これらの操作をするとき、変数はフルネームで指定します。
これらの操作をするとき、変数はフルネームで指定します。
変数の種類 (Kinds of Variables)
スカラー (Scalar)
A scalar variable can store a single string or number. It is usually assigned using [set_variable] or with the {VARIABLE} macros, for example {VARIABLE foo (_"sample value")}
スカラー変数には、一つの文字列または数値が格納できます。これには通常 [set_variable] か {VARIABLE} マクロが使われます。例えば、{VARIABLE foo (_"sample value")} のように書きます。
スカラー変数には、一つの文字列または数値が格納できます。これには通常 [set_variable] か {VARIABLE} マクロが使われます。例えば、{VARIABLE foo (_"sample value")} のように書きます。
The full name of a scalar variable is simply its given name.
スカラー変数のフルネームは単にそれに与えられた名前と同じです。
スカラー変数のフルネームは単にそれに与えられた名前と同じです。
コンテナ (Container)
A container variable can store any number of scalar and/or array variables. There are tags to assign specific information, for instance [store_side].
コンテナ変数には、スカラー変数と配列変数の片方あるいは両方をいくつでも格納できます。特定の情報を代入するためのタグが存在します。それは、例えば [store_side] です。
コンテナ変数には、スカラー変数と配列変数の片方あるいは両方をいくつでも格納できます。特定の情報を代入するためのタグが存在します。それは、例えば [store_side] です。
To refer to a variable `bar` stored in a container `foo` you would write `foo.bar`. An explicit index inside an array is also considered a container.
`foo` コンテナに格納された `bar` という変数を参照するには、`foo.bar` と書くことができます。配列内部の、明確な添字指定(index)もまた、コンテナであると考えられます。<翻訳途中>
`foo` コンテナに格納された `bar` という変数を参照するには、`foo.bar` と書くことができます。配列内部の、明確な添字指定(index)もまた、コンテナであると考えられます。<翻訳途中>
配列 (Array)
An array variable is a numbered sequence of container variables.
配列変数は、コンテナ変数の、順序付けられた一続きのもの(シーケンス)です。<翻訳途中>
配列変数は、コンテナ変数の、順序付けられた一続きのもの(シーケンス)です。<翻訳途中>
There are some specific tags that assign array information, for example [store_unit] and [store_locations]. You can create your own arrays using [set_variable] like this:
配列に情報を代入するためのタグが存在します。例えば、[store_unit] や [store_locations]などです。次のように [set_variable] を使ってあなたの配列を作ることができます。<翻訳途中>
配列に情報を代入するためのタグが存在します。例えば、[store_unit] や [store_locations]などです。次のように [set_variable] を使ってあなたの配列を作ることができます。<翻訳途中>
[set_variable] name=my_awsome_array[0].x value=10 [/set_variable] [set_variable] name=my_awsome_array[1].x value=12 [/set_variable] [set_variable] name=my_awsome_array[2].x value=14 [/set_variable]
If `foo` is the name of an array, `foo[0]` is the full name of its first container variable, `foo[1]` the full name of its second, ..., and `foo.length` is the special variable that always stores the number of containers in `foo`. Hence, if the value stored in `foo.length` is 18, the last container is `foo[17]`.
`foo` が配列名なら、`foo[0]` はその配列の先頭のコンテナ変数の名前で、`foo[1]`は2番目で・・・と続き、そして `foo.length` は `foo` に入っているコンテナ数が常に格納される特殊変数です。つまり、`foo.length` に18が格納されているとすると、末尾のコンテナは `foo[17]` だということになります。
`foo` が配列名なら、`foo[0]` はその配列の先頭のコンテナ変数の名前で、`foo[1]`は2番目で・・・と続き、そして `foo.length` は `foo` に入っているコンテナ数が常に格納される特殊変数です。つまり、`foo.length` に18が格納されているとすると、末尾のコンテナは `foo[17]` だということになります。
If you try to use an Array as if it were a Container, then it will simply use the first `index[0]`. So `$foo.bar` would be the same as `$foo[0].bar`
もしコンテナとして配列を使おうとするなら、単に最初の要素 index[0] を使います。
`$foo.bar` は `$foo[0].bar` と同じでしょう。<翻訳途中>
もしコンテナとして配列を使おうとするなら、単に最初の要素 index[0] を使います。
`$foo.bar` は `$foo[0].bar` と同じでしょう。<翻訳途中>
Note: Do not attempt to store a scalar value to the explicit index of an array, which is a container of scalar variables. Hence referring to a variable named foo[3] as if it were a scalar one is illegal; instead, you would use foo[3].value or foo_3 to store a scalar value. (While it may appear to work to an extent if you ignore this rule, it may also cause undefined behavior. For example, loading a text save of a game that contains such variables will fail with a WML error.)
注意:配列の明確な添え字(index)にスカラー値を格納しようとしないでください。配列の要素は、スカラー変数のコンテナです。つまり、foo[3] と名付けられた変数をスカラー値として参照することはできません。その代わり、スカラー値の格納には、foo[3].value か foo_3 を使うことができます。(このルールを無視すれば、ある程度動作するように見えるものの、そういった挙動は定義されていません。たとえば、こういった変数を含んだ、ゲームが保存されたテキストをロードしようとすれば、WMLエラーを出して失敗するでしょう。)<翻訳途中>
注意:配列の明確な添え字(index)にスカラー値を格納しようとしないでください。配列の要素は、スカラー変数のコンテナです。つまり、foo[3] と名付けられた変数をスカラー値として参照することはできません。その代わり、スカラー値の格納には、foo[3].value か foo_3 を使うことができます。(このルールを無視すれば、ある程度動作するように見えるものの、そういった挙動は定義されていません。たとえば、こういった変数を含んだ、ゲームが保存されたテキストをロードしようとすれば、WMLエラーを出して失敗するでしょう。)<翻訳途中>
変数置換 (Variable substitution)
Variables can be queried in EventWML using [variable] inside an [if] or [while]. Also, when using EventWML, a scalar variable (or scalar variable inside another variable) can be substituted into the right-hand of an '=' assignment to an attribute. Finally, when using [set_variable], the substitution mode can be specified directly.
変数はEventWML内で[if]や[while]内の[variable]を使って呼び出せます。また、EventWMLを使うとき、スカラー変数(または他の変数内のスカラー変数)アトリビュートに'='代入するときの右オペランドの中に置換できます。最後に、[set_variable]を使用するとき、置換モードは直接特定されます。<翻訳途中>
変数はEventWML内で[if]や[while]内の[variable]を使って呼び出せます。また、EventWMLを使うとき、スカラー変数(または他の変数内のスカラー変数)アトリビュートに'='代入するときの右オペランドの中に置換できます。最後に、[set_variable]を使用するとき、置換モードは直接特定されます。<翻訳途中>
When providing attributes, there are 2 different substitution modes:
アトリビュートを指定するとき、2つの置換モードが使えます。<翻訳途中>
アトリビュートを指定するとき、2つの置換モードが使えます。<翻訳途中>
literal
the attribute value is used exactly as provided
アトリビュート値は厳密に、指定されたように使われます。<翻訳途中>
complex
while the provided value contains a $, interpret what is between the rightmost $ and the next | as a full variable name to be queried, and replace $variablename| with the result of this query.
与えられた値が $ を含んでいる間、最右の $ と次の | の間にあるものは完全な変数名が送られたものと見なし、$ variablename| とこのクエリの結果を置き換えます。<翻訳途中>
In certain situations, the | that marks the end of the variable name to be queried can be omitted. The precise rule is:
ある状況下で、| は省略名で呼び出された変数名の末尾を表します。これに関する正確なルール:<翻訳途中>
If there is no |, variable names span letters, digits, underlines, balanced square brackets and some periods. Doubled periods and some periods
that would result in an illegal variable name will not be included. If the variable name ends up being empty (e.g. when using $|), then it will
be replaced by just $, giving you an easy way to include a dollar sign in an interpolated string.
| がない場合、変数名は[a-zA-Z0-9_]と、[]や.で構成されます。2連続の . や 複数の . はインクルードされていない違反の変数名内に結果を返すでしょう。変数名が空で終わった場合(例: $| を使った場合)、単に$で置き換えられるので、これは挿入された文字列の中にドル記号を入れるのを容易にするでしょう。<翻訳途中>
the attribute value is used exactly as provided
アトリビュート値は厳密に、指定されたように使われます。<翻訳途中>
complex
while the provided value contains a $, interpret what is between the rightmost $ and the next | as a full variable name to be queried, and replace $variablename| with the result of this query.
与えられた値が $ を含んでいる間、最右の $ と次の | の間にあるものは完全な変数名が送られたものと見なし、$ variablename| とこのクエリの結果を置き換えます。<翻訳途中>
In certain situations, the | that marks the end of the variable name to be queried can be omitted. The precise rule is:
ある状況下で、| は省略名で呼び出された変数名の末尾を表します。これに関する正確なルール:<翻訳途中>
If there is no |, variable names span letters, digits, underlines, balanced square brackets and some periods. Doubled periods and some periods
that would result in an illegal variable name will not be included. If the variable name ends up being empty (e.g. when using $|), then it will
be replaced by just $, giving you an easy way to include a dollar sign in an interpolated string.
| がない場合、変数名は[a-zA-Z0-9_]と、[]や.で構成されます。2連続の . や 複数の . はインクルードされていない違反の変数名内に結果を返すでしょう。変数名が空で終わった場合(例: $| を使った場合)、単に$で置き換えられるので、これは挿入された文字列の中にドル記号を入れるのを容易にするでしょう。<翻訳途中>
The substitution mode used depends on the attribute being provided:
置換モードは与えられたアトリビュートに依存します:<翻訳途中>
literal
[set_variable] literal=
complex
everywhere else (in EventWML)
どこでも(EventWML内)
置換モードは与えられたアトリビュートに依存します:<翻訳途中>
literal
[set_variable] literal=
complex
everywhere else (in EventWML)
どこでも(EventWML内)
[variables]タグ (The [variables] tag)
The [variables] tag is used in saved games to describe the current value of each variable, and in scenario files for assigning initial values to variables at scenario start.
A scalar variable is assigned using an attribute, where the attribute's key is the variable's given name, and the attribute's value is the value to be stored in the variable.
A container variable with given name foo is assigned using a [foo] tag that contains the definitions for the contained variables.
An array variable with given name foo is assigned using several [foo] tags, where the first tag describes foo[0], the second foo[1], ...
[variable]タグはそれぞれの変数の現在の値を記述するために保存されたゲーム内で使われ、シナリオファイル内で、シナリオのスタート時の初期値を設定します。
スカラー変数は、アトリビュートを使って設定されますが、アトリビュートのキーとは変数に与えられた名前で、アトリビュートの値とは変数に格納された値のことです。
fooという名前を与えられたコンテナ変数は、それに包含された変数の定義を含めるのに[foo]タグを使います。
fooという名前を与えられた配列変数は、いくつかの[foo]タグを使って代入されます。最初のタグの記述はfoo[0]、次のはfoo[1]..となります。
A scalar variable is assigned using an attribute, where the attribute's key is the variable's given name, and the attribute's value is the value to be stored in the variable.
A container variable with given name foo is assigned using a [foo] tag that contains the definitions for the contained variables.
An array variable with given name foo is assigned using several [foo] tags, where the first tag describes foo[0], the second foo[1], ...
[variable]タグはそれぞれの変数の現在の値を記述するために保存されたゲーム内で使われ、シナリオファイル内で、シナリオのスタート時の初期値を設定します。
スカラー変数は、アトリビュートを使って設定されますが、アトリビュートのキーとは変数に与えられた名前で、アトリビュートの値とは変数に格納された値のことです。
fooという名前を与えられたコンテナ変数は、それに包含された変数の定義を含めるのに[foo]タグを使います。
fooという名前を与えられた配列変数は、いくつかの[foo]タグを使って代入されます。最初のタグの記述はfoo[0]、次のはfoo[1]..となります。
自動で格納される変数 ( Automatically stored variables)
- side_number: the number of the current player's side (may be empty during start or prestart events)
- turn_number: the number of the current turn (may be empty during start or prestart events)
- x1: this is the x-coordinate of the location where the most recent event was triggered
- y1: this is the y-coordinate of the location where the most recent event was triggered
- x2: this is the x-coordinate of the location that assisted in triggering the most recent event
- y2: this is the y-coordinate of the location that assisted in triggering the most recent event
- unit: inside an event, this is the unit at $x1,$y1
- second_unit: inside an event, this is the unit at $x2,$y2
- this_unit: inside a standard unit filter, this is the unit currently being considered for a possible match
- side_number: 現在のプレイヤーのサイド番号(startやprestartイベント時には空でしょう)
- turn_number: 現在のターン番号(startやprestartイベント時には空でしょう)
- x1: 一番最近にイベントが起こった場所のX座標
- y1: 一番最近にイベントが起こった場所のY座標
- x2: 一番最近のイベント発生を補助した場所のX座標
- y2: 一番最近のイベント発生を補助した場所のY座標
- unit: イベント内部で、$x1,$y1に相当するユニット
- second_unit: イベント内部で$x2,$y2に相当するユニット
- this_unit: 標準ユニットフィルタ内で、現在マッチ可能と考えられるユニット
例 (Examples)
保存されたゲームと、次の[variables]タグを考えます(またはこのタグを使って新たにシナリオを始める場合)
[variables]
attitude_of_elves=hate
attitude_of_dwarves=love
attitude_of_humans=like
current_opponent=elves
[/variables]
Then,
そして、
そして、
[message]
message="Oh, I see $current_opponent|! They surely $attitude_of_$current_opponent|| us!"
[/message]
displays the message
すると、メッセージが表示されます
すると、メッセージが表示されます
Oh, I see elves! They surely hate us!
別のゲームでの変数を考えます
[variables]
our_side=1
their_side=2
[/variable]
where side 1 has 75 gold, and side 2 50 gold. Then,
サイド1は75ゴールド、サイド2は50ゴールド持っているとき、
サイド1は75ゴールド、サイド2は50ゴールド持っているとき、
[store_side]
side=$our_side
variable=we
[/store_side]
[store_side]
side=$their_side
variable=they
[/store_side]
[message]
message=We have $we.gold gold, they have $they.gold gold.
[/message]
[if]
[variable]
name=we.gold
greater_than=$they.gold
[/variable]
[then]
[message]
message=This should be easy!
[/message]
[/then]
[else]
[message]
message=This will not be easy!
[/message]
[/else]
[/if]
[clear_variable]
name=we
[/clear_variable]
[clear_variable]
name=they
[/clear_variable]
displays the messages
メッセージが表示されます。
メッセージが表示されます。
We have 75 gold, they have 50 gold. This should be easy!
The Code
このコードは、
このコードは、
[store_unit]
[filter]
canrecruit=yes
side=1
[/filter]
variable=leader
[/store_unit]
[message]
message=Our leader's first attack does $leader[0].attack[0].damage damage per hit.
[/message]
[clear_variable]
name=leader
[/clear_variable]
always displays a true sentence.
常に正確な文が表示されます。
常に正確な文が表示されます。
さらなる例 (More Examples)
The implemention of UtilWML makes heavy use of variables, in particular the definition of {FOR_EACH} and {MODIFY_UNIT}. So does the implementation of Victory_Conditions#Victory_by_controlling_villages.
UtilWMLの実装——{FOR_EACH}と{MODIFY_UNIT}の定義では、変数を頻繁に使用しています。
Victory_Conditions#Victory_by_controlling_villagesも同様です。
UtilWMLの実装——{FOR_EACH}と{MODIFY_UNIT}の定義では、変数を頻繁に使用しています。
Victory_Conditions#Victory_by_controlling_villagesも同様です。