Contents |
マクロについてはbranchingで[if():]と[switch():]と、さらに高度なオプションである[macro():] と [token():]を使った例を見てきた。マクロ作成においては分岐は非常に重要な道具の一つだが、これはプレイの最中に発生するさまざまな要素や条件に基づいた判断を自動化することができるからだ。
MapToolのマクロで共通しているもう一つの重要な道具は、同じプロセスの反復だ。例えば、複数の標的に対して複数回の攻撃ロールを繰り返したいような場合(手榴弾を投げ込んだらどの標的が爆発に巻き込まれたかをそれぞれ判定しなければならないだろう)や、技能の一覧をざっと見てそのレーティングと一緒にプリントアウトしたい場合などがこれにあたる。どちらの場合でも、同じ処理を何度か続けて行って、一回ごとに違った結果を得ている。マクロ作成においては、これを反復と呼ぶ(「リスト内をループする」とか「配列の中身を羅列する」とかの表現を見たことがあるだろう。表現はともかく、こうした処理を反復と呼ぶのだ)。
MapTool のマクロには、[count():]、 [while():]、 [for():]、[foreach():]、の4つの反復構造が存在している。これらはいずれもロール・オプションであり、すでに見てきたように:
この先に進む前に、以下の例で、中でも[for():] と [foreach():]で繰り返し使うことになる概念をいくつか説明しておく必要がある。
RPGはプレイを進める上で多くの情報を扱う。能力値、技能、ダイスロール、武器、装備、特殊能力、魔法…などなど、RPGが対応する名前のある全ての情報が溢れている。
基本的には、個々の情報をトークンのプロパティとして作成すれば良い。実際に、記録したいキャラクターの情報を登録することは可能だ。だが、君はきっと「たくさんのプロパティがある」と思うに違いない。その通りだ!
幸いにも、MapToolの情報(またはマクロ変数)をまとめて分類し保存する方法は他にもある。下記の延べる収容方法(正確にはデータタイプと呼ぶ)に関する二つの情報は文字列リストと文字列プロパティ・リストだ。
まず、文字列リストは文字列である。この文字列は、テキストとして扱う英数字から成り立つ(純粋な文字列。数値ではないので、後から数値を追加することは出来ない。ダイスロールではないので MapTool が自動的にロールすることはない。)。
第2に、文字列リストはリストである。区切り文字(セパレーターとも呼ばれる)と見なされる文字に区切られた項目の集まり。区切り文字はリスト内の個々の項目の始まりと終わりを示す。簡潔に言えば「文字列リストは、一覧(例えば色の一覧:blue, green, red, orange, mauve)を表す単体の値である」。
文字列リストのマクロ・コードにおける正確な書式は次の通り:
[h:listOfColors = "blue, green, red, orange, mauve"]
listOfColors the values blue, green, red, orange, mauve. The whole thing is enclosed in double quotes, which tells MapTool that it's a string, and from its very format, MapTool knows that it's a string list.上記例では、変数定義が書かれていて、変数 listOfColors に blue, green, red, orange, mauve が与えられている。MapTool は文字列を表す二重引用符に挟まれ、規則正しく書式化された箇所を文字列リストであると解釈する。
文字列リストは一覧として保持しておきたいあらゆる物(名前の一覧、数値の一覧、ダイス・ロールの一覧など)を含ませることが出来る。
"1d6, 2d8, 1d20", it will not see the first item and see a command to roll 1 six-sided die; instead it will see the character "1", the character "d", and the character "6", all put together. They may look the same to us, but they don't look the same to MapTool - to turn that "1d6" into 1d6 so that MapTool will roll it, we need to use the eval() function to tell MapTool "evaluate that string as if it were a dice roll." You'll see some examples of eval() later on.ただし! 重要なことだが、文字列リスト内の各項目は常に文字列として扱われることを忘れないように。そのため、"1d6, 2d8, 1d20" のような文字列リストを読んだ MapTool は、最初の項目を1つの6面ダイスをロールするコマンドとは見なさず、「1」の文字、「d」の文字、「6」の文字を組み合わせたものとして解釈される。見た目は同じように感じるが、MapTool にとっては異なるものである。「1d6」を MapTool がロールする 1d6 にするには、eval() 関数を使い、MapTool に「文字列をダイスロールとして評価しなさい」と伝える必要がある。後述の eval() の例を見ると良いだろう。
文字列プロパティは、特殊な書式の文字列であることと項目の集まりでできている点で文字列リストによく似ている。それに加えて、文字列プロパティは情報を格納するのにとても有用な機能を備えている。
キー⇔値がつがいになっていることが文字列プロパティの特徴である。基本的に、文字列プロパティの各項目はキーと対になる値を持っている。例えば、次のようなデータを持つ武器があるとして:
この例では:キー「Weapon Name」は値「Broadsword」とペア、キー「Weapon Damage Dice」は値「1d8」とペア、と行った具合にキー=値のペアが連なっている。文字列プロパティは一つの変数に上記のようなペアを示す「規則的な」書式でなりたつ。上記の武器の文字列プロパティは次のようになる:
[h:weapon1 = "name=Broadsword; damageDice=1d8; damageType=Slashing; category=Versatile;"]
この文字列プロパティでは、「=」の左側の単語がキーであり、右側が値である。「;」はセパレーターまたは区切り文字だ。後ほど説明するが、MapToolは文字列プロパティの値を読み取り、変更する特殊な関数がある。
では、繰り返しについて学んで行こう!
まず最初に取り上げる繰り返しの仕組みは[count():]オプションだ。このオプションは、引数に等しい回数ぶん、コロンに続く処理を繰り返す、最も単純な繰り返しである(引数は括弧に挟まれた値または変数であることに注意)。[count():]([c():]に省略可能)の書式は:
[count(repetitions): command]
[count(繰り返し回数): コマンド]
または、
[c(repetitions): command]
[c(繰り返し回数): コマンド]
この例は一目瞭然で説明するまでもないだろう。各要素は:
repetitions: this is the value that tells [count():] how many times to repeat command
command: this is the actual macro command you want count to do over and over again.
繰り返し回数:コマンドを何回繰り返すか[count():]に指示する値。
コマンド:実際に繰り返し実行させたいマクロ・コマンド。
実例を考えてみよう。仮に、君は呪文を使えるキャラクターを持っていて、そのキャラクターが一度に9体の敵に効果のある毒ガス雲を作り出したとしよう。更に、部屋の中には6体の憐れなオークンがいて、君はオーク達に有害な雲を放ち毒殺しようとしている。このゲームのルールでは効果を及ぼしうる対象に対しそれぞれロールを行わなければならないので、6回攻撃それぞれにロールすることになる。すべての攻撃を手動でロールすることもできるが、あらかじめ[count():]を使って繰り返し攻撃のロールを行うマクロを書いておき、ロールする回数を与えるだけでも構わない!
その時に書くマクロは次のようになるはずだ:
[h:attackBonus = 7]Toxic Cloud: [count(numAttacks): 1d20+attackBonus]
[h:attackBonus = 7]毒性雲:[count(numAttacks): 1d20+attackBonus]
ここで書いたものは:
attackBonus, to be used later.
numAttacks is undeclared, MapTool will prompt you for a value before it can start the loop. Once you enter that value, the count loop will process the calculation of 1d20+attackBonus that many times, sending the result to chat each time, and separating each result with a comma.
attackBonusに値を代入。
numAttacksが定義されていないので、繰り返しの処理を始める前にMapToolが値を催促してくる。値を入力すると、COUNTの繰り返し処理が1d20+atackBonusを何度も計算し、その計算結果をコンマで区切りながらチャット・ウィンドウに出力する。
numAttacks): このマクロの出力は次のようになるはずだ(numAttacksの値を求められたときに「4」を入力した場合):
Toxic Cloud: 17, 19, 12, 8
毒性雲:17, 19, 12, 8
roll.count, and it's value is equal to whatever loop you're currently on. So, if you're on the first loop, roll.count is equal to 1; on the second time through, it's equal to 2, and so on. That way, you can use that value in various ways inside your macro command.
[count():]の繰り返しを実行しているとき、今が「何ラウンド目」(何ターン目)であるかが解っていると多くの場面で役に立つので、countの繰り返しを始めた時からMapToolが毎回特殊な変数を用意している。この変数はroll.countと呼び、値に現在繰り返しの何回目にいるかを保持している。つまり、1回目の繰り返しを処理しているときは、roll.countの値は1、2回目の繰り返しでは2。以後同じように増えて行くので、この値をマクロ・コマンドの中で色々な用途に使うことができる。
毒性雲マクロのより高度な実例を見てみよう:
[h:attackBonus = 7] Toxic Cloud vs:<br>[c(numAttacks, "<br>"),CODE:{[attack = 1d20+attackBonus][damage = 1d6 + 2] Target [r:roll.count]: Attack [r:attack]; [damage] damage. }]
[h:attackBonus = 7] 毒性雲:<br>[c(numAttacks, "<br>"),CODE:{[attack = 1d20+attackBonus][damage = 1d6 + 2] 対象 [r:roll.count]:攻撃 [r:attack]、ダメージ [damage]。 }]
いくつかの要素が追加されている。
attackBonus to 7, so we can use it later.
c. We left numAttacks as is, but added a second argument - in this case, a different "separator." All loops in MapTool macros have a default separator, which is the comma. However, you don't always want to separate your results with a comma, right? In this situation, we want to separate them with a line break, so each result is on its own line in chat. So, we put the new separator in - an HTML line break character, or <br>.
attack to the sum of attackBonus and 1d20.
damage to the sum of 1d6+2.
roll.count is in there, which will be replaced with whatever iteration the loop happens to be on.
attackBonusに7を代入。
cを使っている。numAttacksはそのままだが、2つめの引数(標準ではない「区切り文字」)を追加している。MapToolのすべての繰り返し処理はコンマを標準の区切り文字として備えているが、結果を表示するときにいつもコンマを区切り文字として使いたいわけではないだろう? ここでは、チャットにそれぞれの結果を一行づつ表示したいので改行で区切りたいところだ。そこで、HTMLの改行文字(<br>)を区切り文字に指定した。
attackにattackBonusと1d20を合計したものを代入。
damageに1d6+2の合計を代入。
roll.countは現在の繰り返し回数と置き換わっているわけだ。
この出力は次のようになるはずだ:
Toxic Cloud vs:
Target 1: Attack 17; 6 damage.
Target 2: Attack 12; 5 damage.
Target 3: Attack 19; 7 damage.
Target 4: Attack 10; 3 damage.
有毒雲:
対象 1:攻撃 17、ダメージ 6。
対象 2:攻撃 12、ダメージ 5。
対象 3:攻撃 19、ダメージ 7。
対象 4:攻撃 10、ダメージ 3。
では次の繰り返し構造:[while():]を学んでいこう。この構造は、繰り返し回数を決めるために条件文を用いる際、まず初めに考慮に入れるものである(前述の count も値を使用するが、いかなる比較もしていない)。一般的な[while():]の書式は:
[while(condition): command]
[while(条件式): コマンド]
そろそろ、こういったものを読むことに慣れてきたころだろう。
loops < 10 or numDice > 5 or anything you can think of).
loops < 10やnumDice > 5など思いつくものなら何でも)。
つまり、while を用いた繰り返しは「条件式が真であるあいだ、これをやり続けなさい」ということだ。いくつかの例を見てみよう。
これは[while():]の繰り返しの基礎部分を説明するための、非常に簡単な例である。仮に、10から1まで、秒読みを行う必要があるとする。もちろん、さまざまなやり方があるが、ここでは[while():]を使うことにする。このマクロは次のようになる:
[h:num = 10][while(num > 0): num = num - 1]
num is greater than 0, subtract 1 from num, and repeat." Each time through the loop, the value of num will be checked by MapTool. If it is greater than 0, it will let the command num = num-1 happen, and display the result in chat; if num is not greater than 0, then the loop will be halted. The output of this macro looks like:
上記のマクロは、「変数numが 0 より大きい値でいる間、numから1を引き、さらに繰り返しを続けなさい」ということが書いてある。繰り返し中、毎回MapToolがnumの値を確認している。値が0より大きければ、num = num-1のコマンドを実行し、結果をチャットに表示する。もし、numの値が0より大きくなければ、繰り返しを中止する。このマクロの出力は次のようになる:
9,8,7,6,5,4,3,2,1
num having the value of 10, the first time we see any output is when the operation num -1 takes place - so the first thing we see is num - 1, which is 9. 「10」が表示されないことに気づくだろう。繰り返し WHILE は numは10の値とともに開始して、なんらか出力を最初に見るときは、num -1の処理が行われる場合なので、最初に目にする値は num -1の結果、9になるわけだ。
では、もっと複雑な(そしてより楽しい)例を考えてみよう。この例では、相応しい実例を思いつけなかったのでサンプルルールセットは使わない。そこで、次のような状況を想定することにする:
So what we need to do is repeat the operation until either the weapon runs out of ammo, or they roll less than a 15 on their attack. Here's how that macro would look:
武器の弾薬を使い果たすか、ロールの結果が15以下であるまで処理を繰り返すにはどうすれば良いのだろうか。下記のマクロがどのようにしているのか見てみよう:
[h:ammo = 30][h:hit = 1][while(ammo > 0 && hit == 1, "<br>"),CODE:{[h:attackRoll = 1d20][h:ammoSpent = 1d6][h,if(attackRoll > 15): hit = 1; hit = 0][h:ammo = ammo - ammoSpent] Your first attack expends [r:ammoSpent] rounds, and [if(hit==1, "hits.", "misses.")] You have [r:ammo] rounds remaining. }][if(hit==0): "Your turn ends because you missed a target."][if(ammo==0): "Your turn ends because you are out of ammo."]
[h:ammo = 30][h:hit = 1][while(ammo > 0 && hit == 1, "<br>"),CODE:{[h:attackRoll = 1d20][h:ammoSpent = 1d6][h,if(attackRoll > 15): hit = 1; hit = 0][h:ammo = ammo - ammoSpent] 君の攻撃は、[r:ammoSpent]発消費し、[if(hit==1, "命中した。", "失敗した。")] 弾薬は [r:ammo]発残っている。 }][if(hit==0): "攻撃に失敗したので、ターン終了。"][if(ammo==0): "弾薬が無くなったので、ターン終了。"]
ではこのマクロを分析してみよう:
ammo and hit. We set ammo to 30, per the assumptions above, and we set hit to 1, so that the character always gets at least one attack roll (if we didn't set hit to 1, the loop might stop before it started!).
ammo has a value greater than 30, and (remember, two ampersands is the logical operator "and") hit is equal to 1, the loop should go 'round. If either or both of those is not true, then the loop should stop. Also, we set the separator to <br>, so that a new line will be printed each time the loop runs.
hit and ammo - this is critical. If you never change the variables that your conditions are based on, then your loop will never stop.
ammoとhitを設定している。上記の前提の通りammoには30を設定し、キャラクターは常に1回の攻撃ロールを行えるのでhitには1を設定している(もしhitに1を設定しなければ、この繰り返しは処理を開始する前に終わってしまう!)。
ammoの値が30より大きく、そして(二つのアンパサンド(&&)は論理演算子「AND(≒及び)」のことだ)hitが1と等しい状態である間、この繰り返しは処理を繰り返しつづける。この条件の片方または両方が真ではなくなったとき、繰り返しは処理を止める。さらに、繰り返しが実行されるごとに、セパレーターの<br>が新しい行を出力する。
hitとammoに新しい値を代入していることによくよく注意を払うように。これは危険を伴う。条件式はこの変数に基づいており、値が変更されなければ、この繰り返しは止まることなく永遠に処理をし続ける。
重ねて述べるが、WHILEの繰り返しでは、条件式を判定する変数を必ず変更しなければならない。さもなくば永遠に止まることなく処理をし続けてしまう。
このマクロの出力は次のようになる:
Your attack expends 6 rounds, and hits. You have 24 rounds remaining.
Your attack expends 2 rounds, and hits. You have 22 rounds remaining.
Your attack expends 3 rounds, and misses. You have 19 rounds remaining. Your turn ends because you missed a target.
君の攻撃は、6発消費し、命中した。弾薬は24発残っている。
君の攻撃は、2発消費し、命中した。弾薬は22発残っている。
君の攻撃は、3発消費し、失敗した。弾薬は19発残っている。攻撃に失敗したので、ターン終了。
次に取り組む繰り返しの構造は、[for():] ロール・オプションだ。このオプションは、一連のコードを特定の条件に基づいた回数繰り返すので [while():] に少し似ている。また、特定の条件は「カウンターはまだ指定の値に届いているのか?」というものなので [count():] に似ているともいえる。
[for():] の繰り返しの一般的な書式は次の通り:
[for(counter, start, end, stepsize, separator): command]
[for(カウンター, 開始値, 終了値, 増分, 区切り文字): コマンド]
ではやり方を分析していこう:
x or i. For examples below, we'll use i.
counter variable starts at (it can be zero, another variable, or any other numeric value)
counter variable is increasing - in other words, a loop with a positive stepsize - the loop runs as long as counter is less than end
counter variable is decreasing- in other words, a loop with a negative stepsize - the loop runs as long as counter is greater than end
stepsize to 2, then counter will increase by 2 ever iteration). The default stepsize is +1 (that is, by default, the counter variable increments by 1 each time the loop is processed).
x や i などの単純な1文字の変数を指定することが多い。後述の例では、i を使用している。
カウンター変数が最初に指定する値(この値は、ゼロや他の変数、あらゆる数値を指定可能)
カウンター変数が増加していく(増分が正の値の)場合は、カウンター変数が終了値より少ない限り処理を繰り返す。
カウンター変数が減少していく(増分が負の値の)場合は、カウンター変数が終了値より多い限り処理を繰り返す。
増分を2としたら、繰り返しが続く限り、カウンターが2づつ増加する)。標準の増分は+1である(つまり、標準ではカウンター変数は繰り返しの処理ごとに1づつ増加していく)。
この例は、[for():]オプションの個々の要素の働きを説明するものだ。前述の繰り返し構造と同じく、ここでも簡単なカウントダウンを用いる:
[FOR(i,10,0,-2): "i is now " + i]
[FOR(i,10,0,-2): "i は " + i]
この例では、繰り返しの全要素を指定している。
i.
10
0
-2 (the counter decrements by 2 every time the loop processes)
i。
10
0
-2 (繰り返しの処理を行うごとにカウンターを2づつ減少させる)
この出力は次のようになる:
i は 10, i は 8, i は 6, i は 4, i は 2
i is no longer greater than 0. この例では i は 0 の段階には進まないことに注意するように。カウンターが 0 になれば、i はもはや 0 より大きい値ではなくなるからだ。
この例は、文字列リストの項目数と同じ行数の表を作り、チャットに表示する[for():]を使って作る実用的な例だ。
[h:theList = "Strength, Endurance, Dexterity, Intelligence"] [h:numberOfRows = listCount(theList)] <table border="1"> [for(i, 0, numberOfRows, 1, ""): "<tr><td>"+listGet(theList, i)+"</td></tr>"] </table>
上記の例では、出力を作成する便利なコマンドをいくつか使用している。
theList is simply a string list variable containing four elements
i, which starts at 0, and counts up until it reaches numberOfRows. It increases by 1 each loop, and the default separator has been changed to "" so that no extraneous commas are printed to chat.
theList the value of the element that's in the same position as i" - so that it starts with element 0 (all lists start at item 0 in MapTool) and each time we loop through, it gets the next element.
theListは4つの要素を持つ簡単な文字列リストの変数だ
iを使用している。この変数は 0 より始まり、numberOfRowsに達するまで繰り返しごとに1づつ増えていく。区切り文字は、不必要なコンマをチャットに出力しないように、標準のものから""に変更している。
theListのi番目にある要素の値を取り出すように」と伝えている。要素はゼロ番目から始まり(MapToolのリストはすべてゼロ番目から始まる)、繰り返しの終わりまで毎回取得するので、次の要素を取得する。
theList, the table will grow in size to accommodate the new elements.この出力は次のようになる。君がtheListにいくつかの要素を追加すれば、表は追加した数だけ行が増えるであろう。
Strength Endurance Dexterity Intelligence
The [for():] loop structure lets you repeat a set of commands a specified number of times, with flexible beginning, ending, and steps. That looping method is applicable to many things, and can be looked at as a very "general" way to loop - it gives you lots of flexibility with where you start and end, and can be used for many operations.
[for():]の繰り返しの構造は、一連のコマンドを柔軟な開始値、終了値、増分により指定した回数実行する。この繰り返しの手法は開始値と終了値を決め、多くの式を使うことで、多彩な柔軟性に富んでいる。そのため、多くの場面に応用でき、繰り返しにおける非常に『一般的』な手法と言える。
However, frequently loops are used to go through a list of items that is already established, and it is kind of a pain to have to make sure to count each list, then assign the variables in a [for():] loop, and make sure you can figure out how the counter variable corresponds to the position of an item in a list. So, a different kind of for loop - one that handles most of that without bothering you about it - also exists. This one is called [foreach():].
しなしながら、頻繁に使われる繰り返しでは既に作られているリスト内の項目を順番に見ていくものであり、リストの数を調べて[for():]の繰り返しの変数を定義し、リスト内の項目の位置を示すカウンター変数がいくらであるか求めるなければならないのは、ある種の苦痛である。そしため、煩わしい多くの設定を省いたFORの繰り返しの亜種を用意している。これを[foreach():]と呼ぶ。
In a [foreach():] loop, the looping structure is given two arguments: the name of a string list, and a variable. The variable takes on the value of each element in the list, in turn, as the looping structure iterates. That's a bit confusing, so first, let's look at the general structure of a [foreach():] loop:
[foreach():]の繰り返し構造には、2つの引数を用いる:文字列リストの名前と一つの変数だ。この変数は繰り返し構造が反復する度に、リストの各要素の値を保持する。少しばかり混乱しやすいので、まずは[foreach():]の繰り返しの一般的な構造を見ていこう:
[foreach(item, list): command]
foreach() to work on
item in list
foreach()で処理を行う文字列リスト
リスト内の一連の項目に対して実行する処理。
To explain that in plain English: assume for a moment that there you have the names of several targets (NPC tokens) that your character wants to attack at the same time. You need to make an attack roll against each target, which is equal to 1d20 + 7, but you have to roll separately for each target.
説明のためわかりやすくしてみよう。君のキャラクターが同時に攻撃しようとしている複数の名前のある対象(NPCトークン)があるとしよう。君は各対象に攻撃ロール(1d20+7)を行う必要があるが、個々の対象に別々にロールしなければならない。
You could write out the attacks each time like this:
この行為は次のように書き出すことができる。
I attack target 1: [1d20+7]<br> I attack target 2: [1d20+7]<br> I attack target 3: [1d20+7]<br> I attack target 4: [1d20+7]<br>
対象 1 への攻撃: [1d20+7]<br> 対象 2 への攻撃: [1d20+7]<br> 対象 3 への攻撃: [1d20+7]<br> 対象 4 への攻撃: [1d20+7]<br>
And so forth and so on. Not so bad if you have 3 targets. But what if you have 6? Or 12?
その他、色々な書き方があるだろ。相手が3体なら悪くないが、6体ならどうか?12体なら?
So instead, what if you created a single variable that was a list of the names of each target? Then, you can use the [foreach():] loop to go through the list one by one and let you make the roll with a very efficient little bit of code. [foreach():] may be a little hard to explain, but once you understand what it can do, you will see how useful it can be!
その代わりとして、各対象の名称のリストの変数を作るとしたらどうだろうか? リストの一つ一つを取り出しながら一か所のコードで効率的にロールを行うために、[foreach():]の繰り返しを使うことができる。[foreach():]は少しばかり説明が難しいが、何ができるかを理解すれば、いかに便利か解るだろう!
Now, let's jump to some examples.
では、例を見てみよう。
This simple example will go through a string list, and list the value of each element in the list, from beginning to end.
この単純な例では文字列リストを通して、リストの初めから終わりまでのそれぞれの要素の値を取り出して一覧していく。
[h:theList = "18, Bob, 29, Foo, 1009, Snorkel"] [foreach(item, theList, "<br>"): item]
In the above macro, we've created a [foreach():] loop that takes the list variable theList, and goes to each element in that list, and assigns the value of that element to the variable item. We've set the separator to the HTML code for a line break, and then -- after the colon -- instructed the macro to print the value of the variable item to the chat window.
上記のマクロでは、リストの変数 theList を扱う [foreach():] を作り、リスト内の各要素を取り出し、その要素の値を変数 item に割り当てている。改行を表す HTML コードをセパレーターとして設定し、コロンに続けて変数 item の値をチャットウィンドウに出力するマクロ指定している。
The output of that macro looks like:
このマクロを出力は次のようになる。
18
Bob
29
Foo
1009
Snorkel
Do you see what happened there? The foreach() option went to each element in theList, said, "the variable item is now equal to the element," and then printed the value of item to chat.
なにが起きているの解っただろうか? この foreach() オプションは theList の各要素を取り出して「変数 item はこの要素と同じである」と宣言し、item の値をチャットウィンドウに出力している。
Now, let's look at the example described in the beginning. Remember how we had those target names to attack? Here's how we'd do that:
では最初にこの例を見てみよう。攻撃する対象の名前を持つ方法をどうするか覚えいるだろうか?次の通りだ。
[h:targetList = "Orc 1, Goblin 2, Orc 4, Zombie 17, Big Boss"] [foreach(target, targetList, "<br>"),CODE: { [h:attackRoll = 1d20+7] I attack [r:target] with an attack roll of [r:attackRoll] }]
[h:targetList = "オーク 1, ゴブリン 2, オーク 4, ゾンビ 17, 親玉"] [foreach(target, targetList, "<br>"),CODE: { [h:attackRoll = 1d20+7] [r:target] に攻撃し、攻撃ロールは [r:attackRoll] 。 }]
targetList, as discussed.
targetList, assigning its value to the variable target. So, the first time through, target has the value of the first item in targetList - in other words, target is equal to Orc 1. The second time through, target equals the second item in the list, and so on.
attackRoll. This is recalculated on every loop, so it's different for each target.
target and the variable attackRoll in the appropriate places.
targetList を定義している。
targetList の各要素を取り出し、その値を変数 target に割り当てている。最初の繰り返しでは target は targetList の最初の値(つまり target は オーク 1となる)を持っている。繰り返しの2回目では target はリストの2番目の値となり、以降順々に繰り返されていく。
attackRollと名付けた変数を計算している。この変数は繰り返しごとに再々計算されるので、それぞれの target ごとに異なる結果となる。
target と attacRoll の値を埋め込みチャットへの出力を生成している。
The output of that macro, when sent to chat, looks like:
このマクロの出力がチャットウィンドウに送るものは次の通り。
I attack Orc 1 with an attack roll of 12
I attack Goblin 2 with an attack roll of 11
I attack Orc 4 with an attack roll of 21
I attack Zombie 17 with an attack roll of 17
I attack Big Boss with an attack roll of 9
オーク 1 に攻撃し、攻撃ロールは 12
ゴブリン 2 に攻撃し、攻撃ロールは 11
オーク 4 に攻撃し、攻撃ロールは 21
ゾンビ 17 に攻撃し、攻撃ロールは 17
親玉 に攻撃し、攻撃ロールは 9
That about covers the looping basics for MapTool macros. The examples shown above are very simple, of course - just enough to show you how these work. But looping is incredibly useful for many applications in a MapTool macro, from generating multiple die rolls to building tables to editing token properties, so make sure to experiment with it.
ここでは、MapTool マクロにおける基本的な繰り返し処理を学んできた。上記の例は非常に単純なものである(もちろん例示する作業には純分なものだ)。しかし、繰り返し処理は MapTool マクロを、複数のダイスロールの生成から、テーブルの構築、トークンのプロパティの編集などに応用するうえで非常にに有用なものでありので、ぜひこの機能を試してもらいたい。