abort/ja: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(最初の訳)
 
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 25: Line 25:


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
abort(abrt)
abort(abrt)
</source>
</syntaxhighlight>


'''パラメーター'''
'''パラメーター'''
Line 37: Line 37:
<!--The following example will create a dialog box for the user to enter a value for the variable named blah, if the user clicks on cancel then res will be 0 so the abort() function will cause the macro to terminate, otherwise res will not be 0 so the macro will continue.-->
<!--The following example will create a dialog box for the user to enter a value for the variable named blah, if the user clicks on cancel then res will be 0 so the abort() function will cause the macro to terminate, otherwise res will not be 0 so the macro will continue.-->
次の例では、blah という変数にユーザーが値を入力するダイアログボックスを作成し、ユーザーがキャンセルをクリックすると res が 0 になり、abort() 関数によってマクロが終了し、そうでない場合は res が 0 にならないためマクロが継続する。
次の例では、blah という変数にユーザーが値を入力するダイアログボックスを作成し、ユーザーがキャンセルをクリックすると res が 0 になり、abort() 関数によってマクロが終了し、そうでない場合は res が 0 にならないためマクロが継続する。
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: res = input("blah")] [h: abort(res)]
[h: res = input("blah")] [h: abort(res)]
</source>
</syntaxhighlight>


<!--The following example discards any output in the macro.-->
<!--The following example discards any output in the macro.-->
次の例では、マクロ内の出力をすべて破棄する。
次の例では、マクロ内の出力をすべて破棄する。
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
Hah! you will never see this! [abort(0)]
Hah! you will never see this! [abort(0)]
</source>
</syntaxhighlight>


<!--The following line can be used to protect macros that only the GM should run-->
<!--The following line can be used to protect macros that only the GM should run-->
以下の行は、GM以外が実行してはならないマクロを保護するために使用できる。
以下の行は、GM以外が実行してはならないマクロを保護するために使用できる。
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: abort(isGM())]
[h: abort(isGM())]
</source>
</syntaxhighlight>


<!--The following line can be used to silently end a macro that can only be run from a [[Trusted Macro]]-->
<!--The following line can be used to silently end a macro that can only be run from a [[Trusted Macro]]-->
次の行は、[[Trusted Macro]] からしか実行できないマクロを静かに終了させるために使用できる。
次の行は、[[Trusted Macro]] からしか実行できないマクロを静かに終了させるために使用できる。
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: abort(isTrusted())]
[h: abort(isTrusted())]
</source>
</syntaxhighlight>


===使用の注意===<!--Usage Notes-->
===使用の注意===<!--Usage Notes-->
Line 68: Line 68:


====呼び出し側マクロ====<!--Calling Macro-->
====呼び出し側マクロ====<!--Calling Macro-->
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
<!-- Call the getAmmo library macro -->
<!-- Call the getAmmo library macro -->
[MACRO("getAmmo@Lib:test"): "arrows"]
[MACRO("getAmmo@Lib:test"): "arrows"]
君は [r:macro.return] 本の矢を持っている。
君は [r:macro.return] 本の矢を持っている。
</source>
</syntaxhighlight>


====呼び出されるマクロ====<!--Called Macro-->
====呼び出されるマクロ====<!--Called Macro-->
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
<!-- getAmmo macro in Lib:test token -->
<!-- getAmmo macro in Lib:test token -->
[h: macro.return = 0]
[h: macro.return = 0]
[h: abort(json.contains(ammunition, macro.args))]
[h: abort(json.contains(ammunition, macro.args))]
[h: macro.return = json.get(ammunition, macro.args)]
[h: macro.return = json.get(ammunition, macro.args)]
</source>
</syntaxhighlight>


====結果====<!--結果-->
====結果====<!--結果-->

Latest revision as of 17:26, 14 March 2023

Languages:  English  • 日本語


abort() Function

Introduced in version 1.3b42
マクロの実行を条件付きで中止するために使用する。abort() の引数が 0 の場合、マクロの実行は停止し、すべてのマクロ出力は破棄される。abort() の引数が0以外の場合は、マクロの実行は継続される。

なお、マクロが中止されると、マクロの出力のみが破棄され、マクロに加えられた変更自体は取り消されない事に注意。

この関数の一般的な用途は以下の通り。

  • input() 関数で作成された入力ダイアログでキャンセルボタンがクリックされた場合にマクロを終了する。
  • マクロで生成されたすべての出力を破棄して、実質的に『無出力』マクロを作成する。
  • 特定の条件が満たされない場合、マクロを静かに終了させる。
マクロの終了時にエラーメッセージを表示したい場合は、 assert() 関数を参照。

Usage

abort(abrt)

パラメーター

  • abrt - 0 if the abort function should abort the macro, nonzero if it should not.
  • abrt - 0 abort 関数がマクロを中止すべきである場合はゼロ、そうでない場合は非ゼロ。

Examples

次の例では、blah という変数にユーザーが値を入力するダイアログボックスを作成し、ユーザーがキャンセルをクリックすると res が 0 になり、abort() 関数によってマクロが終了し、そうでない場合は res が 0 にならないためマクロが継続する。
[h: res = input("blah")] [h: abort(res)]

次の例では、マクロ内の出力をすべて破棄する。

Hah! you will never see this! [abort(0)]

以下の行は、GM以外が実行してはならないマクロを保護するために使用できる。

[h: abort(isGM())]

次の行は、Trusted Macro からしか実行できないマクロを静かに終了させるために使用できる。

[h: abort(isTrusted())]

使用の注意

他のマクロ(例えば library token など)から呼び出されたマクロを中止する場合、実行中のマクロだけでなく、すべてのマクロが中止される。

1.5.0以降では、macro.catchAbort を使用してこの動作を変更することができる。

呼び出し側マクロ

<!-- Call the getAmmo library macro -->
[MACRO("getAmmo@Lib:test"): "arrows"]
君は [r:macro.return] 本の矢を持っている。

呼び出されるマクロ

<!-- getAmmo macro in Lib:test token -->
[h: macro.return = 0]
[h: abort(json.contains(ammunition, macro.args))]
[h: macro.return = json.get(ammunition, macro.args)]

結果

assuming ammunition = { "arrows" : 30 }

トークン名: 君は 30 本の矢を持っている。

assuming ammunition = { "bolts" : 20 }

(出力無し)

See Also

Version Changes

  • 1.3b49 - No message is displayed if called from a macroLink.
  • 1.5.0 - catch an abort with macro.catchAbort

Languages:  English  • 日本語