Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
GDScript 警告系統
GDScript 警告系統能完善 靜態型別 (但即使不使用靜態型別也能運作)。這個系統可以協助你在開發過程中發現難以察覺的錯誤,避免這些錯誤在執行時發生。
你可以在「專案設定」中的 GDScript 分類下設定警告選項:
備註
必須啟用 進階設定,才能在側邊欄看到 GDScript 分類。若未啟用進階設定,也可以直接搜尋「GDScript」。
在腳本編輯器的狀態列上可以看到目前開啟的 GDScript 檔案所產生的警告。下方範例中有兩個警告:
若要在檔案中忽略單一警告,可以使用 @warning_ignore 標註。你也可以點擊警告描述左側的忽略連結,Godot 會自動在對應行上方加入標註,該程式碼就不會再觸發該警告:
若要在檔案內的某個區塊忽略多個警告,可以使用 @warning_ignore_start 及 @warning_ignore_restore 標註。如果想要忽略直到檔案結尾,可以省略 @warning_ignore_restore。
The names of the warnings to ignore match the names of the project settings.
For example, to ignore the warning configured by the
debug/gdscript/warnings/unused_variable
project setting, use @warning_ignore("unused_variable").
An autocompletion dialog displays when entering a warning name in the
annotation, listing all available warnings.
警告並不會阻止遊戲執行,但你可以選擇將警告視為錯誤。如此一來,除非修正所有警告,否則專案將無法編譯。在「專案設定」的 GDScript 分類找到你想要設定的警告類型,並啟用將此警告視為錯誤的選項。下方範例是將 unused_variable 警告設為錯誤後的畫面: