Introduction to Macro Branching/ja: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
Line 308: Line 308:
1行目で気づいた人もいるだろう。ここでは一つの行で、{{roll|h}} と {{roll|if}}の''二つ''のロール・オプションを使っている。この二つのオプションはコンマで区切られていて、コロンは最後のロール・オプションの後ろ、{{code|真のときのコマンド}}と{{code|偽の時のコマンド}}のセクションの前にある。
1行目で気づいた人もいるだろう。ここでは一つの行で、{{roll|h}} と {{roll|if}}の''二つ''のロール・オプションを使っている。この二つのオプションはコンマで区切られていて、コロンは最後のロール・オプションの後ろ、{{code|真のときのコマンド}}と{{code|偽の時のコマンド}}のセクションの前にある。


===IF and CODE===
===IF CODE===


So what if you want to do more than one thing based on a comparison? Say, set a bunch of variables to a certain value? For that, you use the {{roll|code}} roll option.  
So what if you want to do more than one thing based on a comparison? Say, set a bunch of variables to a certain value? For that, you use the {{roll|code}} roll option.  
比較の結果としてやりたいことが複数あったらどうしたらいいだろうか? 例えば、複数の変数にそれぞれ値を代入するとか? それには{{roll|code}}ロール・オプションが使える。


Like all roll options, {{roll|code}} is put at the beginning of the line, separated from other roll options by a comma. Macro programming convention (that is, the way most macro writers seem to do it) is to put {{roll|code}} as the last roll option in the list. So, the general format you will see in a macro is likely to be:
Like all roll options, {{roll|code}} is put at the beginning of the line, separated from other roll options by a comma. Macro programming convention (that is, the way most macro writers seem to do it) is to put {{roll|code}} as the last roll option in the list. So, the general format you will see in a macro is likely to be:
他のロール・オプションと同じように、{{roll|code}}は行の先頭に置き、他のロール・オプションとはコンマで区切る。マクロプログラミング規約(要は、ほとんどのマクロがそうなってるって意味だ)では、{{roll|code}} をロール・オプションの一番最後につけることになっている。だから、マクロの中では一般にはこんな風になる:
<blockquote>
<source lang="mtmacro">
[roll_option1, roll_option2, code: macro_commands]
</source>
</blockquote>


<blockquote>
<blockquote>
Line 321: Line 331:


The second component of the {{roll|code}} option is the curly bracket ({ }). You use these to enclose multiple commands as a single group. Remember the format of the {{roll|if}} roll option?
The second component of the {{roll|code}} option is the curly bracket ({ }). You use these to enclose multiple commands as a single group. Remember the format of the {{roll|if}} roll option?
{{roll|code}}オプションの二番目の要素は中カッコ({})だ。これを使って複数のコマンドを一つの群にまとめる。{{roll|if}}ロール・オプションの文法を覚えているかな?


<blockquote>
<blockquote>
<source lang="mtmacro">
<source lang="mtmacro">
[if(comparison): command_if_true; command_if_false]
[if(comparison): command_if_true; command_if_false]
</source>
</blockquote>
<blockquote>
<source lang="mtmacro">
[if(comparison): 真のときのコマンド; 偽のときのコマンド]
</source>
</source>
</blockquote>
</blockquote>


Well, the {{roll|code}} option lets you replace {{code|command_if_true}} and {{code|command_if_false}} with ''multiple'' macro commands. Let's look at an example:  
Well, the {{roll|code}} option lets you replace {{code|command_if_true}} and {{code|command_if_false}} with ''multiple'' macro commands. Let's look at an example:  
さて、{{roll|code}}オプションでは {{code|真のときのコマンド}} と {{code|偽のときのコマンド}} に''複数の''マクロ・コマンドを置くことができる。例を見てみよう:


Suppose we write a macro to look at a variable called {{code|attackRoll}}. We want to compare it to a number (the target number), which is held by the variable {{code|targetNumber}}. Here's what we want the macro to do:
Suppose we write a macro to look at a variable called {{code|attackRoll}}. We want to compare it to a number (the target number), which is held by the variable {{code|targetNumber}}. Here's what we want the macro to do:
これから{{code|attackRoll}}という変数の値を調べるマクロを書くとしよう。そしてこれをある値(目標値)と比較しようと考えている。この値は{{code|targetNumber}}という変数に格納されている。マクロにやらせたいのはこういうことだ:


If {{code|attackRoll}} is greater than or equal to {{code|targetNumber}}, the macro should:
If {{code|attackRoll}} is greater than or equal to {{code|targetNumber}}, the macro should:
Line 339: Line 361:
* Set {{code|damageRoll}} to the result of the dice roll 1d8+4.
* Set {{code|damageRoll}} to the result of the dice roll 1d8+4.
* Output a string telling the user the results.
* Output a string telling the user the results.
もし {{code|attackRoll}} が {{code|targetNumber}} 以上なら:
* {{code|attackUsed}} に "yes" をセット
* {{code|attackResult}} に "命中" をセット
* {{code|attackRecharge}} に 3 をセット
* {{code|damageRoll}} には 1d8+4 の結果をセット
* ユーザーにその結果を知らせる文字列を表示する


If {{code|attackRoll}} is ''not'' greater than or equal to {{code|targetNumber}}, the macro should:
If {{code|attackRoll}} is ''not'' greater than or equal to {{code|targetNumber}}, the macro should:
Line 347: Line 377:
* Set {{code|damageRoll}} to "no"  
* Set {{code|damageRoll}} to "no"  
* Output a string to chat telling the user the results.
* Output a string to chat telling the user the results.
もし {{code|attackRoll}} が {{code|targetNumber}}''未満''なら:
* {{code|attackUsed}} に "yes" をセット
* {{code|attackResult}} に "外れ" をセット
* {{code|attackRecharge}} に 3 をセット
* {{code|damageRoll}} には "no" をセット
* ユーザーにその結果を知らせる文字列を表示する


Here's how to do it:
Here's how to do it:
では、以下にそのマクロを載せる:


<blockquote>
<blockquote>
Line 372: Line 412:
</source>
</source>
</blockquote>
</blockquote>
<blockquote>
<source lang="mtmacro">
[h:attackRoll = 1d20]
[h:targetNumber = 15]
[h,if(attackRoll >= targetNumber), code:
{
  [attackUsed = "yes"]
  [attackResult = "命中"]
  [attackRecharge = 3]
  [damageRoll = 1d8+4]
};
{
  [attackUsed = "yes"]
  [attackResult = "外れ"]
  [attackRecharge = 3]
  [damageRoll = 0]
}]
あなたの攻撃は [attackResult] で、与えたダメージは [damageRoll] 点。 次の攻撃ができるまで [attackRecharge] ラウンドかかる。
</source>
</blockquote>


There's a lot going on here, but the important thing to look for is the CODE option in the very first line, and the curly braces. The curly braces enclose multiple separate commands, but say to MapTool, "treat these as one thing". So in the example above:
There's a lot going on here, but the important thing to look for is the CODE option in the very first line, and the curly braces. The curly braces enclose multiple separate commands, but say to MapTool, "treat these as one thing". So in the example above:
ここではいろいろなことをしているが、注目して欲しいのは一番最初の行にある CODE オプションと、中カッコだ。中カッコの中には複数のコマンドが入っているが、MapToolに対してこれを「一つのものとして扱う」よう指示していることになる。従って、上の例はこのように動作する:


* We declare two variables, {{code|attackRoll}} and {{code|targetNumber}}, and give them initial values (in this case, {{code|attackRoll}} will be the result of a 1d20 roll, and {{code|targetNumber}} is set to 15).  
* We declare two variables, {{code|attackRoll}} and {{code|targetNumber}}, and give them initial values (in this case, {{code|attackRoll}} will be the result of a 1d20 roll, and {{code|targetNumber}} is set to 15).  
* 二つの変数 {{code|attackRoll}} と {{code|targetNumber}} を宣言し、初期値を与える(この場合、{{code|attackRoll}} は 1d20 の結果、{{code|targetNumber}} は15になるはずだ)。
* We set up the comparison (putting an h, in front - remember, that will hide the results from chat, so you don't see all the calculations in the if statement).
* We set up the comparison (putting an h, in front - remember, that will hide the results from chat, so you don't see all the calculations in the if statement).
* 比較条件を設定する(まず最初に h を置く。このオプションをつけるとその結果をチャットに表示しなくなる。従って、この if 文の計算結果は見えなくなる)。
* We put {{roll|code}} in there to warn MapTool that each part of the {{roll|if}} roll option -  {{code|command_if_true}} and {{code|command_if_false}} - will actually consist of multiple separate commands.  
* We put {{roll|code}} in there to warn MapTool that each part of the {{roll|if}} roll option -  {{code|command_if_true}} and {{code|command_if_false}} - will actually consist of multiple separate commands.  
* {{roll|if}}ロール・オプションの中の、{{code|真のときのコマンド}} と {{code|偽のときのコマンド}}のそれぞれの部分に{{roll|code}}を置いて、この部分の中には複数のコマンドが入るのだということをMapToolにあらかじめ報せておく。
* We put a colon after the word {{code|code}}, to mark off the end of all the roll options. There is only ONE colon in the line!
* We put a colon after the word {{code|code}}, to mark off the end of all the roll options. There is only ONE colon in the line!
* {{code|code}}文の後ろにコロンを置き、ロール・オプションの終端であることを知らせる。この行にあるコロンはこれ一つだけ!
* We use a { to mark the start of the {{code|command_if_true}} portion of the IF statement. We then put in our commands, each one separately and enclosed in square brackets. Once finished, we ''close'' that section of the IF statement with a }, and put a semicolon on the end (remember, the IF roll option needs a semicolon to separate {{code|command_if_true}} from {{code|command_if_false}}.
* We use a { to mark the start of the {{code|command_if_true}} portion of the IF statement. We then put in our commands, each one separately and enclosed in square brackets. Once finished, we ''close'' that section of the IF statement with a }, and put a semicolon on the end (remember, the IF roll option needs a semicolon to separate {{code|command_if_true}} from {{code|command_if_false}}.
* IF文の中の、{{code|真のときのコマンド}} の最初に { を置く。それからそれぞれ大カッコでくくったコマンドを並べていく。全部終わったら、このセクションを } で閉じ、最後にセミコロンをつける( IF ロール・オプションでは、{{code|真のときのコマンド}} と {{code|偽のときのコマンド}} を区切るのにセミコロンが必要だということを思い出して欲しい)
* We do the same process for the {{code|command_if_false}} section - a { followed by a series of commands, and then closed with a }.  
* We do the same process for the {{code|command_if_false}} section - a { followed by a series of commands, and then closed with a }.  
* 上と同じ作業を {{code|偽のときのコマンド}} のセクションについても行う。 { の後に一連のコマンドを並べ、最後に } で閉じる。
* We make sure to close off the '''''whole''''' if statement with another square bracket ( ] ). Remember, an IF roll option is still just a macro command, and all macro commands must be enclosed in '''[ ]'''.  
* We make sure to close off the '''''whole''''' if statement with another square bracket ( ] ). Remember, an IF roll option is still just a macro command, and all macro commands must be enclosed in '''[ ]'''.  
* ここでこの if 文'''''全体を'''''大カッコ( ] )でくくっておくこと。 IF ロール・オプションもマクロ・コマンドの一つであり、全てのマクロ・コマンドは'''[ ]'''でくくられていなければならない。
* Finally, we write some text, with the several variables we have inserted at appropriate points, to be sent to chat when the macro runs.
* Finally, we write some text, with the several variables we have inserted at appropriate points, to be sent to chat when the macro runs.


* 最後に、それぞれの変数を適当な場所に埋め込んだテキストを書き、マクロが実行されたときにチャットに送り込まれるようにしておく


'''NOTE''': The CODE roll option only works with ''other roll options''. You would not use this with the {{func|if}} ''function''. That is a bit confusing, but just remember: CODE only goes with other roll options.
'''NOTE''': The CODE roll option only works with ''other roll options''. You would not use this with the {{func|if}} ''function''. That is a bit confusing, but just remember: CODE only goes with other roll options.
'''注意''': CODE ロール・オプションは''他のロール・オプション''と組み合わせたときにだけ動作する。''関数''である{{func|if}} とは組み合わせられない。ちょっとややこしいかも知れないが、「 CODE は ロール・オプションと組み合わせてしか使えない」とだけ、覚えておいて欲しい。


==SWITCH: Choosing from Many Options==
==SWITCH: Choosing from Many Options==

Revision as of 04:30, 17 September 2009

{{#customtitle:はじめてのマクロ分岐|はじめてのマクロ分岐}}

INTERMEDIATE
THIS IS AN INTERMEDIATE ARTICLE

はじめに

When you write a macro, you'll frequently find yourelf wanting to either repeat an operation several times, or to choose from several options based on the outcome of a macro command. In game terms, you might want to make an damage roll several times in a row (say, one time for each enemy caught by a grenade blast), or you might want your macro to give you a damage roll if you hit, and say You missed! if you miss.

マクロを書いていると、何度も同じ処理を繰り返したり、マクロ・コマンドの結果に応じて複数の選択肢から一つを選んで実行したりしたくなることが良くある。ゲームを例に取るなら、(例えば手榴弾の爆発に複数の敵を巻き込んだときのように、)何度も続けてダメージ・ダイスを振りたいこともあるだろうし、また、もし攻撃が命中したらダメージ・ダイスを振り、外したらハズレ! と表示してくれるようなマクロを作りたいと考えるかも知れない。

In programming jargon, those concepts are called looping (where you go through a process repeatedly, or "loop through it"), and branching (where your program - in this case, the macro - "branches" down different paths). The MapTool macro language has several roll options (and one function) to let you branch and/or loop your commands.

プログラム用語では、こういう概念を繰り返し(一つの処理を繰り返す)と分岐(プログラム―ここではマクロだが―が異なる複数の処理に枝分かれする)と呼ぶ。MapToolのマクロ言語にはダイスを振るための複数のオプション(や関数)があり、これであなたの命令を分岐・繰り返しさせることができる。

Finally, because there are a lot of times when you'll want to do several things at the same time when you branch or loop, there's a special roll option called code that tells MapTool to treat several macro commands as a single "unit" when you loop or branch. That may sound confusing, but you'll see what it all means shortly!

そして最後に、分岐や繰り返しを使って一度に複数の事をさばきたいと感じるのは良くあることなので、繰り返しや分岐の際に複数のマクロ・コマンドをまとめて一つの「単位」として扱えるcodeというオプションも用意されている。ちょっと分かりにくいかも知れないが、すぐに分かるようになる。

Since there's a lot of ground to cover, this tutorial will cover branching (running different commands based on some condition). The Introduction to Macro Loops will handle looping (running a process repeatedly, until you wish it to stop).

話さなければならないことが沢山あるので、このチュートリアルでは分岐(ある条件によって異なる命令を実行する)について説明することにする。繰り返し(ある処理を止めるまで繰り返す)についてはIntroduction to Macro Loopsで解説する。

想定する読者

We're going to get to using these options pretty fast, so I assume you've read the Introduction to Macro Writing and have knowledge of how to create a new macro and use some very basic commands in it (like creating a variable or a dice roll).

これから急ぎ足でいろいろなオプションを使っていくことになる。そんなわけで、Introduction to Macro Writingを読み終え、新しいマクロの作り方を知っていて、その中に含まれていた(変数を作ったり、ダイス振りをしたりするなどの)基本的なコマンドが使えると想定することにする。

There are a couple concepts that should be introduced first, since they're going to be a great way to illustrate some of the branching concepts (and looping concepts, in the Introduction to Macro Loops. You'll get an explanation of the new concepts below.

まず最初にいくつかの概念を理解してもらうが、これは分岐という概念を(そしてこの先Introduction to Macro Loopsで説明する繰り返しの概念を)理解するという大変な作業を行うために必要だからだ。その新しい概念について、これから説明していこう。

新しい概念: CODE オプション

Normally, in any branching or looping technique, MapTool lets you do one thing - that is, one command. So if you had a statement that said "if a condition is true, do something cool," then "something cool" can only be one single thing - you might roll some dice, or assign a variable, or print out some text to the chat window. However, you couldn't roll some dice, assign a variable, assign another variable, do some math, and then print out something all in that statement. That's too many operations.

MapToolでは、分岐や繰り返しの技法を使うと、一つのことしかできないのが普通だ。この一つのこととは、つまりコマンド1個ということだ。だから「もしある条件が満たされたなら、なにかイケてることをしろ」では、この「なにかイケてること」の部分には一つのことしか入れられない。ダイスを振るとか、変数を宣言するとか、チャット・ウィンドウになにかのテキストを表示するとか、だ。しかし、ダイスを振って、変数を宣言して、さらにもう一つ変数を宣言して、計算を行い、それからそのなにかを出力する、といった処理はできない。処理の数が多すぎるからだ。

If you could only do one thing when you branch or loop, macros would be very limited - so the macro language supports a special roll option called [code():], which indicates to MapTool that you want to do several things at once, but have them all happen as a single "branch" or "loop." You would group these several commands inside a pair of curly braces ( { } ).

分岐や繰り返しを使うと一つのことしかできないというのでは、マクロの可能性は限られたものになってしまう。そこで、マクロ言語は特殊なロールのオプションを用意している。これが[code():]だ。これは、複数の処理を行いたいが、それが「分岐」や「繰り返し」の一つとして行われるべきだということをMapToolに伝えるためのものだ。複数のコマンドを一組の中カッコ({})の中に書く。

The examples below will use the [code():] option, so you can see how it works.

以下の例では[code():]のオプションを使っている。その仕組みが分かってもらえるだろう。

新しい概念: 比較演算子と論理演算子

In macro writing, you're going to want to compare values together a lot - is my dice roll greater than 20? Are my hit points less than 0? Does that weapon name equal "Warhammer?" All of these are handled via comparison operators and logical operators.

マクロを作成する場合、二つの数値を比べたいと考えることがよくある。ダイスの出目は20より大きいか? ヒットポイントは 0 より小さいか? その武器の名前は "Warhammer" と等しいか?

Comparison Operator is programming jargon for the symbols we use to have MapTool compare two values to each other in certain ways (an operator is a symbol that performs an operation - for instance, the + symbol is an operator that adds things together).

比較演算子とはプログラミングで用いる用語で、MapToolで二つの値を特定の基準で比べあうときに使う記号のことだ(演算子とは、ある演算を行うための記号だ)。例えば+記号は加算を表す。

A Logical Operator is a symbol you use to instruct MapTool in what order to consider comparisons, and how to group comparisons together. The comparison and logical operators are described below:

論理演算子は、MapToolに対してどういう順番で比較を解釈したらよいか、それをどうまとめるかを教えるための記号だ。比較演算子と論理演算子については以下で説明する:

In the examples below, the if() function is used to illustrate the examples. It's described in more detail later, but the basic "format" of the if() function is this:

以下の例では、if() を使って説明している。これについては後でもう少し詳しく解説するが、基本的なif()の「文法」は以下の通りだ:

if(comparison, value_if_true, value_if_false)

if(比較, 真のときの値, 偽のときの値)


  • Comparison is where you do your actual comparison (greater than, less than, etc.)
  • Value_if_true is where you put the output or value if the comparison is true
  • Value_if_false is, obviously, where you put the output or value if the comparison is false
  • 比較は、実際に比較を行う部分(~より大きい、~より小さい、など)
  • 真のときの値は、比較結果が正しいときに出す出力や取る値を書く部分
  • 偽のときの値は、当然、比較結果が正しくないときに出す出力や取る値を書く部分 

比較演算子

The symbols below are the comparison operators. Remember that you must always think of these comparisons from the reference point of the value on the left side. So, in the comparison value1 > value2, you read it based on the left side: "is value1 greater than value2. This is the rule for comparisons in MapTool - the left side of the operator is the "point of view."

比較演算子を以下に挙げる。こうした比較は常に左辺値を起点として考えねばならない点に注意すること。だから、value1 > value2という比較では、左辺値を基本として「value1value2よりも大きい」と読むことになる。これはMapToolで比較を行う場合の規則だ。演算子の左辺値がかならず比較の「視点」となる。

  • ==: "is equal to;" this is the operator you use to see if one value is equal to another. Be careful - it has two equals signs in a row (remember, one equal sign is already reserved for assigning values to variable). An example of this comparison would look like [if(hit == "yes", "you hit!", "you missed!")]
  • ==: 「~と等しい」 これは両方の値が等しいことを確認するための演算子だ。間違いやすいので注意して欲しいが、等号は二つ並んでいる(等号一つは、左辺値が変数であることを表すときに使われることを思い出して欲しい)。比較の例はこのようになる。[if(hit == "yes", "命中!", "外した!")]
  • >: "is greater than; use this to see if the value on the left side is greater than the value on the right. For example: "yes"等しくないなら、変数output"外れ"の値を代入する。
  • It then prints a short line of text and the value of output to chat.
  • そして、短いテキストとoutputの値をチャットに表示する。

You'll note that the first line - the line that uses if - has two roll options on the same line: [h:] and [if():]. You'll also see that they are separated by a comma, and the colon goes after the last roll option, and before the commands in the command_if_true and command_if_false sections.

1行目で気づいた人もいるだろう。ここでは一つの行で、[h:][if():]二つのロール・オプションを使っている。この二つのオプションはコンマで区切られていて、コロンは最後のロール・オプションの後ろ、真のときのコマンド偽の時のコマンドのセクションの前にある。

IF と CODE

So what if you want to do more than one thing based on a comparison? Say, set a bunch of variables to a certain value? For that, you use the [code():] roll option.

比較の結果としてやりたいことが複数あったらどうしたらいいだろうか? 例えば、複数の変数にそれぞれ値を代入するとか? それには[code():]ロール・オプションが使える。

Like all roll options, [code():] is put at the beginning of the line, separated from other roll options by a comma. Macro programming convention (that is, the way most macro writers seem to do it) is to put [code():] as the last roll option in the list. So, the general format you will see in a macro is likely to be:

他のロール・オプションと同じように、[code():]は行の先頭に置き、他のロール・オプションとはコンマで区切る。マクロプログラミング規約(要は、ほとんどのマクロがそうなってるって意味だ)では、[code():] をロール・オプションの一番最後につけることになっている。だから、マクロの中では一般にはこんな風になる:

[roll_option1, roll_option2, code: macro_commands]
[roll_option1, roll_option2, code: macro_commands]

The second component of the [code():] option is the curly bracket ({ }). You use these to enclose multiple commands as a single group. Remember the format of the [if():] roll option?

[code():]オプションの二番目の要素は中カッコ({})だ。これを使って複数のコマンドを一つの群にまとめる。[if():]ロール・オプションの文法を覚えているかな?

[if(comparison): command_if_true; command_if_false]
[if(comparison): 真のときのコマンド; 偽のときのコマンド]

Well, the [code():] option lets you replace command_if_true and command_if_false with multiple macro commands. Let's look at an example:

さて、[code():]オプションでは 真のときのコマンド偽のときのコマンド複数のマクロ・コマンドを置くことができる。例を見てみよう:

Suppose we write a macro to look at a variable called attackRoll. We want to compare it to a number (the target number), which is held by the variable targetNumber. Here's what we want the macro to do:

これからattackRollという変数の値を調べるマクロを書くとしよう。そしてこれをある値(目標値)と比較しようと考えている。この値はtargetNumberという変数に格納されている。マクロにやらせたいのはこういうことだ:

If attackRoll is greater than or equal to targetNumber, the macro should:

  • Set attackUsed to "yes"
  • Set attackResult to "hits"
  • Set attackRecharge to 3
  • Set damageRoll to the result of the dice roll 1d8+4.
  • Output a string telling the user the results.

もし attackRolltargetNumber 以上なら:

  • attackUsed に "yes" をセット
  • attackResult に "命中" をセット
  • attackRecharge に 3 をセット
  • damageRoll には 1d8+4 の結果をセット
  • ユーザーにその結果を知らせる文字列を表示する

If attackRoll is not greater than or equal to targetNumber, the macro should:

  • Set attackUsed to "Yes"
  • Set attackResult to "misses"
  • Set attackRecharge to 3
  • Set damageRoll to "no"
  • Output a string to chat telling the user the results.

もし attackRolltargetNumber未満なら:

  • attackUsed に "yes" をセット
  • attackResult に "外れ" をセット
  • attackRecharge に 3 をセット
  • damageRoll には "no" をセット
  • ユーザーにその結果を知らせる文字列を表示する

Here's how to do it:

では、以下にそのマクロを載せる:

[h:attackRoll = 1d20]
[h:targetNumber = 15]

[h,if(attackRoll >= targetNumber), code:
{
  [attackUsed = "yes"]
  [attackResult = "hits"]
  [attackRecharge = 3]
  [damageRoll = 1d8+4]
};
{
  [attackUsed = "yes"]
  [attackResult = "misses"]
  [attackRecharge = 3]
  [damageRoll = "no"]
}]

Your attack [attackResult], and you do [damageRoll] damage. Your attack will recharge in [attackRecharge] rounds.
[h:attackRoll = 1d20]
[h:targetNumber = 15]

[h,if(attackRoll >= targetNumber), code:
{
  [attackUsed = "yes"]
  [attackResult = "命中"]
  [attackRecharge = 3]
  [damageRoll = 1d8+4]
};
{
  [attackUsed = "yes"]
  [attackResult = "外れ"]
  [attackRecharge = 3]
  [damageRoll = 0]
}]

あなたの攻撃は [attackResult] で、与えたダメージは [damageRoll] 点。 次の攻撃ができるまで [attackRecharge] ラウンドかかる。


There's a lot going on here, but the important thing to look for is the CODE option in the very first line, and the curly braces. The curly braces enclose multiple separate commands, but say to MapTool, "treat these as one thing". So in the example above:

ここではいろいろなことをしているが、注目して欲しいのは一番最初の行にある CODE オプションと、中カッコだ。中カッコの中には複数のコマンドが入っているが、MapToolに対してこれを「一つのものとして扱う」よう指示していることになる。従って、上の例はこのように動作する:

  • We declare two variables, attackRoll and targetNumber, and give them initial values (in this case, attackRoll will be the result of a 1d20 roll, and targetNumber is set to 15).
  • 二つの変数 attackRolltargetNumber を宣言し、初期値を与える(この場合、attackRoll は 1d20 の結果、targetNumber は15になるはずだ)。
  • We set up the comparison (putting an h, in front - remember, that will hide the results from chat, so you don't see all the calculations in the if statement).
  • 比較条件を設定する(まず最初に h を置く。このオプションをつけるとその結果をチャットに表示しなくなる。従って、この if 文の計算結果は見えなくなる)。
  • We put [code():] in there to warn MapTool that each part of the [if():] roll option - command_if_true and command_if_false - will actually consist of multiple separate commands.
  • [if():]ロール・オプションの中の、真のときのコマンド偽のときのコマンドのそれぞれの部分に[code():]を置いて、この部分の中には複数のコマンドが入るのだということをMapToolにあらかじめ報せておく。
  • We put a colon after the word code, to mark off the end of all the roll options. There is only ONE colon in the line!
  • code文の後ろにコロンを置き、ロール・オプションの終端であることを知らせる。この行にあるコロンはこれ一つだけ!
  • We use a { to mark the start of the command_if_true portion of the IF statement. We then put in our commands, each one separately and enclosed in square brackets. Once finished, we close that section of the IF statement with a }, and put a semicolon on the end (remember, the IF roll option needs a semicolon to separate command_if_true from command_if_false.
  • IF文の中の、真のときのコマンド の最初に { を置く。それからそれぞれ大カッコでくくったコマンドを並べていく。全部終わったら、このセクションを } で閉じ、最後にセミコロンをつける( IF ロール・オプションでは、真のときのコマンド偽のときのコマンド を区切るのにセミコロンが必要だということを思い出して欲しい)
  • We do the same process for the command_if_false section - a { followed by a series of commands, and then closed with a }.
  • 上と同じ作業を 偽のときのコマンド のセクションについても行う。 { の後に一連のコマンドを並べ、最後に } で閉じる。
  • We make sure to close off the whole if statement with another square bracket ( ] ). Remember, an IF roll option is still just a macro command, and all macro commands must be enclosed in [ ].
  • ここでこの if 文全体を大カッコ( ] )でくくっておくこと。 IF ロール・オプションもマクロ・コマンドの一つであり、全てのマクロ・コマンドは[ ]でくくられていなければならない。
  • Finally, we write some text, with the several variables we have inserted at appropriate points, to be sent to chat when the macro runs.
  • 最後に、それぞれの変数を適当な場所に埋め込んだテキストを書き、マクロが実行されたときにチャットに送り込まれるようにしておく

NOTE: The CODE roll option only works with other roll options. You would not use this with the if() function. That is a bit confusing, but just remember: CODE only goes with other roll options.

注意: CODE ロール・オプションは他のロール・オプションと組み合わせたときにだけ動作する。関数であるif() とは組み合わせられない。ちょっとややこしいかも知れないが、「 CODE は ロール・オプションと組み合わせてしか使えない」とだけ、覚えておいて欲しい。

SWITCH: Choosing from Many Options

The if() function and the [if():] roll option both let you pick from two options - either do something when the comparison is true, or do something different when the comparison is false. But life - and RPG's - are not always so black and white. When you want to do different things based on one of many options, you use the [switch():] roll option.

The general format is:

[switch(val):
case case_value1: command_1;
case case_value2: command_2;
case case_value3: command_3;
default: command_Default]

What's happening here is this:

  • MapTool is looking at the value of the variable val
  • MapTool then looks at each of the case statements in the switch, and compares val to case_value1, case_value2, and case_value3
  • When MapTool finds a match - that is, val is equal to one of those cases, the appropriate command (either command_1, command_2, or command_3) is executed, and then MapTool exits the switch statement (which just means, once it's found a match, it does what that case says, and then stops checking for matches).

Suppose, for example, that the we wanted a macro that would automatically assign the right Armor value to a token, based on the token's Class. If you've been following along, you might recognize the Armor value as one of the attributes in the Sample Ruleset. If you visit the Sample Ruleset page, you'll see that a character can have one of several armor values, based on the character's class:

  • A Warrior has an armor value of 6
  • A Rogue has an armor value of 2
  • A Wizard has an armor value of 1
  • A Priest has an armor value of 4

So, let's say we want a macro to ask us for the value of the variable class, and then use that variable to assign the right Armor value. Here's how we'd do it:

[h:class = "Rogue"]

[h,switch(class):
case "Warrior": Armor = 6;
case "Rogue": Armor = 2;
case "Wizard": Armor = 1;
case "Priest": Armor = 4;
default: Armor = 0]

Your Armor Value is [Armor].

What the above example does is:

  • Look at the value for class - if you try this out, it will always show the value for "Rogue." If you alter the [h:class="Rogue"] line, you can see how changing that value affects the switch statement).
  • Compare what you put in there with the four different cases - checking to see if class is equal to "Warrior", "Rogue", "Wizard", or "Priest".
  • If class equals any of those (and we mean EXACTLY equals - case sensitive, no spaces, an exact match), run the command to set the variable Armor to the appropriate value.
  • If no match is found, do whatever follows the default option (in other words, set Armor to 0.
  • Stop looking for matches, and move on.

SWITCH and CODE

The [code():] option can be used with a [switch():] option, in a similar manner as [if():]. There are a couple tricky bits, but if you follow the pattern given in the examples, it should work for you.

To do a [switch():] option with [code():], the general format is:

[switch(val),code:
case case_1: { commands_for_case_1};
case case_2: { commands_for_case_2};
case case_3: { commands_for_case_3};
default: { commands_for_default}]

An actual example can be drawn from the Sample Ruleset as well. Not only does a character's class indicate his or her armor value, but also the list of "Beginning Powers" from which the character can draw. Suppose we wanted to set not only the armor value, but also a variable called beginningPowers. To do that, you'd write a SWITCH that looks like:

[h,switch(class),code:
case "Warrior":
{
  [Armor = 6]
  [beginningPowers = "Sword, Shield Bash, Bow, Shield, Torch"]
};
case "Rogue":
{
  [Armor = 2]
  [beginningPowers = "Dagger, Hide, Backstab, Pick Lock, Torch"]
};
case "Wizard":
{
  [Armor = 1]
  [beginningPowers = "Dagger, Staff, Light, Lightning Bolt, Fire Ball"]
};
case "Priest":
{
  [Armor = 4]
  [beginningPowers = "Mace, Heal, Protect, Banish Undead, Torch"]
};
default:
{
  [Armor = 0]
  [beginningPowers = "Fists, Feet"]
}]

Your Armor Value is [Armor] and your beginning powers are [beginningPowers].

As you can see, each different case is treated as a single block of operations - so you need to put curly braces for each separate case, and separate them all with the semicolon. At the very end, we put a closing square bracket (]), to finish the whole command. Again, what has happened is that the CODE option and the curly braces have allowed you to replace a single command, like command_for_case_1, with a group of commands.

Also, you'll see that I've added in some line breaks so that each separate group of operations is easier to read - MapTool is cool with that, because extra line breaks inside a command (remember, commands are enclosed within [ ]) are ignored. This is nice, because it makes the macros much easier to read.

Advanced Branching Options

The two options illustrated above are the most common branching options used in macro writing. However, they are not the only options for branching macros - there are two others, which involve either leaving one macro entirely to call on another, or changing the focus (that is, what token is the Current Token) of a macro temporarily. Since these are fairly complex operations all on their own, you'll find them in the More Branching Options guide.