タイポや「グローバル」宣言の欠落など、エラーを示す可能性のある特定の条件に対する警告の有効・無効を設定します。
#Warn WarningType, WarningMode
型:文字列
If omitted, it defaults to All. Otherwise, specify the type of warning to enable or disable.
VarUnset: Before the script starts to run, display a warning for the first reference to each variable which is never used in any of the following ways:
LocalSameAsGlobal: Before the script starts to run, display a warning for each undeclared local variable which has the same name as a global variable. これは、グローバル変数を関数内で宣言してから代入しようとした場合に起こるエラーを防止するためのものです。もし本当にローカルな変数であることを意図していたのであれば、local x
やstatic y
などの宣言を用いて警告を抑制することができます。
この警告は、デフォルトでは無効になっています。
#Warn g := 1 ShowG() { ; 関数が一度も呼び出されない場合でも警告は表示されます。 ; global g ; <-- グローバル変数に代入するために必要です。 g := 2 } ShowG MsgBox g ; 宣言がない場合、上記はローカルな "g "に割り当てられる。
Unreachable: Before the script starts to run, show a warning for each line that immediately follows a Return
, Break
, Continue
, Throw
or Goto
at the same nesting level, unless that line is the target of a label. そんなセリフがあっても実行されることはない。
コードが到達できないことを意図している場合(例えば、リターン
によってコードのブロックを一時的に無効にした場合、またはホットキーやホットストリングをコメントアウトすることによって一時的に無効にした場合)、到達できないコードもコメントアウトすることを検討してください。また、最初の到達不可能な行の上にラベルを定義することで、警告を抑制することも可能です。
All: Apply the given WarningMode to all supported warning types.
型:文字列
省略された場合は、MsgBoxがデフォルトとなる。Otherwise, specify a value indicating how warnings should be delivered.
MsgBox: Show a message box describing the warning. なお、メッセージボックスが解除されると、スクリプトは通常通り実行されます。
StdOut: Send a description of the warning to stdout (the program's standard output stream), along with the filename and line number. これにより、SciTEのような高級エディタがスクリプトを中断することなく警告を捕らえることができ、ユーザーは後でエディタの出力ペインから問題のある行にジャンプすることができます。
OutputDebug: Send a description of the warning to the debugger for display. デバッガがアクティブでない場合は、何の効果もありません。詳しくは、OutputDebugをご覧ください。
Off: Disable warnings of the given WarningType.
If this directive is unspecified in the script, all warnings are enabled and use the MsgBox mode, except for LocalSameAsGlobal, which is disabled.
VarUnset、LocalSameAsGlobal、Unreachableの警告を出すチェックは、すべてのディレクティブがパースされた後、スクリプトが実行される前に行われます。したがって、スクリプト内の位置は重要ではありません(また、他のディレクティブと同様、#Warnは条件付きで実行することはできません)。
ただし、複数の#Warnディレクティブの並び順は重要です。ある予告を設定した最後の発生で、その予告のモードが決定されます。したがって、例えば、以下の2つのステートメントは、LocalSameAsGlobal以外のすべての警告を有効にする効果を合わせ持っています。
#Warn All #Warn LocalSameAsGlobal, Off