Automate Updating a Token Property/ja: Difference between revisions
(Created page with "{{Languages|Automate Updating a Token Property}}{{Translation}} {{DISPLAYTITLE:トークン特性値を自動的に更新する|トークン特性値を自動的に更新す...") |
m (Taustin moved page automate Updating a Token Property/ja to Automate Updating a Token Property/ja) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 18: | Line 18: | ||
最初に、番号の入力を求めます。MapToolにはこの機能が組み込まれています。必要なことは、まだ存在しない変数名を使用することです。MapToolはプロンプトをポップアップ表示します。変数の名前はプロンプトの一部なので、わかりやすい名前を使用します。{{code|AmountOfDamage}}はどうでしょうか? | 最初に、番号の入力を求めます。MapToolにはこの機能が組み込まれています。必要なことは、まだ存在しない変数名を使用することです。MapToolはプロンプトをポップアップ表示します。変数の名前はプロンプトの一部なので、わかりやすい名前を使用します。{{code|AmountOfDamage}}はどうでしょうか? | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[ damage = AmountOfDamage ] | [ damage = AmountOfDamage ] | ||
</ | </syntaxhighlight> | ||
<div style="color:gray">Notice the extra variable name and the equals sign? That tells MapTool to calculate whatever is on the right of the equals sign and store the result into the variable on the left. In this case, there's no formula, so this becomes simply a copy -- from the variable {{code|AmountOfDamage}} to {{code|damage}}. But when MapTool tries to read the value of the variable and it doesn't exist, the popup will automatically appear! That's perfect for what we want!</div> | <div style="color:gray">Notice the extra variable name and the equals sign? That tells MapTool to calculate whatever is on the right of the equals sign and store the result into the variable on the left. In this case, there's no formula, so this becomes simply a copy -- from the variable {{code|AmountOfDamage}} to {{code|damage}}. But when MapTool tries to read the value of the variable and it doesn't exist, the popup will automatically appear! That's perfect for what we want!</div> | ||
Line 30: | Line 30: | ||
次のステップは、それを{{code|HP}}プロパティから差し引くことです。幸いなことに、前の段落で学んだことは、再び使うことができます。 | 次のステップは、それを{{code|HP}}プロパティから差し引くことです。幸いなことに、前の段落で学んだことは、再び使うことができます。 | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[ damage = AmountOfDamage ] | [ damage = AmountOfDamage ] | ||
[ HP = HP - damage ] | [ HP = HP - damage ] | ||
</ | </syntaxhighlight> | ||
<div style="color:gray">This time the second line calculates the formula on the right ({{code|HP - damage}}) and stores the result into ... {{code|HP}}? Isn't that going to screw up our {{code|HP}} value?</div> | <div style="color:gray">This time the second line calculates the formula on the right ({{code|HP - damage}}) and stores the result into ... {{code|HP}}? Isn't that going to screw up our {{code|HP}} value?</div> | ||
Line 57: | Line 57: | ||
<div style="color:gray">We already know that we have a {{code|HP}} and {{code|HPmax}} properties, so when they are healed up we simply need to copy the value in {{code|HPmax}} into {{code|HP}}. That should give you what you need to create a simple one-line macro:</div> | <div style="color:gray">We already know that we have a {{code|HP}} and {{code|HPmax}} properties, so when they are healed up we simply need to copy the value in {{code|HPmax}} into {{code|HP}}. That should give you what you need to create a simple one-line macro:</div> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[ HP = HPmax ] | [ HP = HPmax ] | ||
</ | </syntaxhighlight> | ||
<div style="color:gray">Simple, right? But for the sake of argument, let's expand on this a bit. Instead of restoring all of the hit points to the creature, we will prompt the user for the number of hours that the creature will be resting. For my demonstration, I'm assuming that there's a property named {{code|Level}}. If it rests for less than 24 hours, it gets back {{code|Level*2}} hit points. If it rests for 24 hours or more, it gets back {{code|Level*6}}.</div> | <div style="color:gray">Simple, right? But for the sake of argument, let's expand on this a bit. Instead of restoring all of the hit points to the creature, we will prompt the user for the number of hours that the creature will be resting. For my demonstration, I'm assuming that there's a property named {{code|Level}}. If it rests for less than 24 hours, it gets back {{code|Level*2}} hit points. If it rests for 24 hours or more, it gets back {{code|Level*6}}.</div> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[ hours = NumberOfHours ] | [ hours = NumberOfHours ] | ||
[ healing = if(hours < 24, Level * 2, Level * 6) ] | [ healing = if(hours < 24, Level * 2, Level * 6) ] | ||
[ HP = HP + healing ] | [ HP = HP + healing ] | ||
</ | </syntaxhighlight> | ||
<div style="color:gray">You may notice the {{func|if}} function on the second line. One word of warning when using the {{func|if}} function: both the true and the false sections are executed! For that reason, you may want the {{roll|if}} roll option instead. Note that the syntax is slightly different between the two, so be careful about which one you choose.</div> | <div style="color:gray">You may notice the {{func|if}} function on the second line. One word of warning when using the {{func|if}} function: both the true and the false sections are executed! For that reason, you may want the {{roll|if}} roll option instead. Note that the syntax is slightly different between the two, so be careful about which one you choose.</div> | ||
Line 85: | Line 85: | ||
<div style="color:gray">Using the simple variable prompt explained above becomes clumsy, so let's use the {{func|input}} function instead:</div> | <div style="color:gray">Using the simple variable prompt explained above becomes clumsy, so let's use the {{func|input}} function instead:</div> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[ cancel = input("SpendSurge | 1 | Spend Healing Surge? | CHECK", | [ cancel = input("SpendSurge | 1 | Spend Healing Surge? | CHECK", | ||
"GainSurge | 1 | Gain Surge HP? | CHECK", | "GainSurge | 1 | Gain Surge HP? | CHECK", | ||
Line 91: | Line 91: | ||
"GainTempHP | 0 | Temporary Hit Points") ] | "GainTempHP | 0 | Temporary Hit Points") ] | ||
[ abort(cancel) ] | [ abort(cancel) ] | ||
</ | </syntaxhighlight> | ||
<div style="color:gray">This will prompt you for all possible variations detailed above, in a single input screen. ((image needed)) Then, you can use some {{func|if}} functions or {{roll|if}} roll options to update all the properties involved. This example assumes that you're using the token properties {{code|HP}}, {{code|TempHP}}, {{code|SurgeRemain}} and {{code|SurgeValue}}:</div> | <div style="color:gray">This will prompt you for all possible variations detailed above, in a single input screen. ((image needed)) Then, you can use some {{func|if}} functions or {{roll|if}} roll options to update all the properties involved. This example assumes that you're using the token properties {{code|HP}}, {{code|TempHP}}, {{code|SurgeRemain}} and {{code|SurgeValue}}:</div> | ||
< | <syntaxhighlight lang="mtmacro" line> | ||
[ cancel = input("SpendSurge | 1 | Spend Healing Surge? | CHECK", | [ cancel = input("SpendSurge | 1 | Spend Healing Surge? | CHECK", | ||
"GainSurge | 1 | Gain Surge HP? | CHECK", | "GainSurge | 1 | Gain Surge HP? | CHECK", | ||
Line 105: | Line 105: | ||
[ HP = HP + ExtraHeal ] | [ HP = HP + ExtraHeal ] | ||
[ TempHP = max(TempHP, GainTempHP) ] | [ TempHP = max(TempHP, GainTempHP) ] | ||
</ | </syntaxhighlight> | ||
<div style="color:gray">Notice that the {{func|abort}} function was used after the {{func|input}} function to make sure that, in case the user clicked "Cancel" in the input window, the properties wouldn't be updated.</div> | <div style="color:gray">Notice that the {{func|abort}} function was used after the {{func|input}} function to make sure that, in case the user clicked "Cancel" in the input window, the properties wouldn't be updated.</div> | ||
[[Category:How To]] | [[Category:How To]] | ||
{{Languages|Automate Updating a Token Property}} | {{Languages|Automate Updating a Token Property}} |
Latest revision as of 23:59, 3 May 2023
This section expects that you are already familiar with how to add macro buttons to the MapTool user interface.
Example: Updating Hit Points
HP
. Now we want some easy way to update HP
, so we're going to create a macro button that executes a macro.ヒットポイントを表すプロパティがあるとします。プロパティをHP
と呼びます。HP
を簡単に更新する方法が必要なので、マクロを実行するマクロボタンを作成します。
HP
, so the user can use a positive number to represent damage and a negative number to represent healing. (We'll show another approach later.)まず、これをどのように機能させるかを検討します。画面にウィンドウがポップアップし、ユーザーに番号の入力を求めます。この数値はHP
から差し引かれるため、ユーザーは正の数値を使用して損傷を表し、負の数値を使用して修復を表すことができます。(別のアプローチを後で示します。)
AmountOfDamage
?最初に、番号の入力を求めます。MapToolにはこの機能が組み込まれています。必要なことは、まだ存在しない変数名を使用することです。MapToolはプロンプトをポップアップ表示します。変数の名前はプロンプトの一部なので、わかりやすい名前を使用します。AmountOfDamage
はどうでしょうか?
[ damage = AmountOfDamage ]
AmountOfDamage
to damage
. But when MapTool tries to read the value of the variable and it doesn't exist, the popup will automatically appear! That's perfect for what we want!余分な変数名と等号に注目してください。これにより、MapToolは等号の右側にあるものをすべて計算し、その結果を左側の変数に格納します。この場合、数式はないので、変数AmountOfDamage
からdamage
のコピーになります。しかし、MapToolが変数の値を読み取ろうとしたときにその変数が存在しない場合は、ポップアップが自動的に表示されます。それは私たちが欲しいものにぴったりです!
HP
property. Fortunately, what you learned in the last paragraph can be used again:次のステップは、それをHP
プロパティから差し引くことです。幸いなことに、前の段落で学んだことは、再び使うことができます。
[ damage = AmountOfDamage ]
[ HP = HP - damage ]
HP - damage
) and stores the result into ... HP
? Isn't that going to screw up our HP
value?今度は、次の行で右の式(HP - damage
)が計算され、結果が...HP
? それではHP
の価値が台無しになってしまうのではないでしょうか。
HP
is a property, the result is stored back into the token's property. If you were to right-click on the token and save it to an external file, the new value of HP
is stored with it. When the token is later reloaded, that value will come with it.いいえ、失敗することはありませんが、その値を結果に置き換えます。また、HP
はプロパティであるため、結果はトークンのプロパティに格納されます。トークンを右クリックして外部ファイルに保存すると、HP
の新しい値がそのトークンとともに保存されます。トークンを後で再ロードすると、その値がトークンに含まれます。
-
to a +
. The first option is easy because it puts the burden on the user! The second option is really an option -- who wants to edit their macro every time they want to switch from damage to healing? Another choice not listed above would be to create a second macro. Then there could be one macro for adding damage and one for adding healing.代わりにヒットポイントに追加する場合は、負の数値を入力するか、-
を+
に変更します。最初の選択肢は、ユーザに負担をかけるので簡単です!2番目のオプションは、実際にはオプションです。損傷から修復に切り替えるたびにマクロを編集したいと思うでしょうか。上記以外の方法として、2つ目のマクロを作成することもできます。次に、損傷を追加するマクロと修復を追加するマクロがあります。
HP
.) And try adding the second macro as well, just for the practice. (Believe me, the more practice you get early in the process, the easier it will become later on.)これをもっと美しくするためには、まだいくつか必要なことがありますが、それらは将来のステップです。MapToolで作成したトークンで今すぐ試してみてください。(既定のプロパティ形式 Basic には、HP
という名前のプロパティが含まれています。)練習のために、二つ目のマクロも追加してみてください。(早い段階で練習すればするほど、後で練習しやすくなります。)
Example: Let's Rest for a Minute...
HP
and HPmax
properties, so when they are healed up we simply need to copy the value in HPmax
into HP
. That should give you what you need to create a simple one-line macro:[ HP = HPmax ]
Level
. If it rests for less than 24 hours, it gets back Level*2
hit points. If it rests for 24 hours or more, it gets back Level*6
.[ hours = NumberOfHours ]
[ healing = if(hours < 24, Level * 2, Level * 6) ]
[ HP = HP + healing ]
Example: One Macro to Rule Them All
- spend a Healing Surge and regain HP
- spend a Healing Surge without gaining HP
- gain HP as if you spent a Healing Surge
- gain a set number of HP (alone or in addition to a Healing Surge)
- gain Temporary HP (alone or in addition to a Healing Surge, and temporary HPs don't stack)
[ cancel = input("SpendSurge | 1 | Spend Healing Surge? | CHECK",
"GainSurge | 1 | Gain Surge HP? | CHECK",
"ExtraHeal | 0 | Additional Healing",
"GainTempHP | 0 | Temporary Hit Points") ]
[ abort(cancel) ]
HP
, TempHP
, SurgeRemain
and SurgeValue
:[ cancel = input("SpendSurge | 1 | Spend Healing Surge? | CHECK",
"GainSurge | 1 | Gain Surge HP? | CHECK",
"ExtraHeal | 0 | Additional Healing",
"GainTempHP | 0 | Temporary Hit Points") ]
[ abort(cancel) ]
[ if(SpendSurge): SurgeRemain = SurgeRemain - 1 ]
[ if(GainSurge): HP = HP + SurgeValue ]
[ HP = HP + ExtraHeal ]
[ TempHP = max(TempHP, GainTempHP) ]