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.

Script

繼承: Resource < RefCounted < Object

被繼承: CSharpScript, GDScript, ScriptExtension

作為資源儲存的類。

說明

作為資源儲存的類。腳本可以擴充所有以它為實例的物件的功能。

這是所有腳本的基底類別,不應直接使用。嘗試使用此類建立新腳本將導致錯誤。

腳本子類別的 new 方法會建立新的實例。如果一個現有的物件的類與腳本的基底類別之一相配對,Object.set_script() 會擴充該物件。

教學

屬性

String

source_code

方法

bool

can_instantiate() const

Script

get_base_script() const

StringName

get_global_name() const

StringName

get_instance_base_type() const

Variant

get_property_default_value(property: StringName)

Variant

get_rpc_config() const

Dictionary

get_script_constant_map()

Array[Dictionary]

get_script_method_list()

Array[Dictionary]

get_script_property_list()

Array[Dictionary]

get_script_signal_list()

bool

has_script_method(method_name: StringName) const

bool

has_script_signal(signal_name: StringName) const

bool

has_source_code() const

bool

instance_has(base_object: Object) const

bool

is_abstract() const

bool

is_tool() const

Error

reload(keep_state: bool = false)


屬性說明

String source_code 🔗

  • void set_source_code(value: String)

  • String get_source_code()

腳本的原始程式碼,如果原始程式碼不可用,則為空字串。當設定時,不會自動重新載入類的實作。


方法說明

bool can_instantiate() const 🔗

如果該腳本可以被產生實體,則返回 true


Script get_base_script() const 🔗

返回由該腳本直接繼承的腳本。


StringName get_global_name() const 🔗

Returns the class name associated with the script, if there is one. Returns an empty string otherwise.

To give the script a global name, you can use the class_name keyword in GDScript and the [GlobalClass] attribute in C#.

class_name MyNode
extends Node

StringName get_instance_base_type() const 🔗

返回腳本的基底類別型別。


Variant get_property_default_value(property: StringName) 🔗

返回指定屬性的預設值。


Variant get_rpc_config() const 🔗

Returns a Dictionary mapping method names to their RPC configuration defined by this script.


Dictionary get_script_constant_map() 🔗

返回一個包含常數名稱及其值的字典。


Array[Dictionary] get_script_method_list() 🔗

Returns the list of methods in this Script.

Note: The dictionaries returned by this method are formatted identically to those returned by Object.get_method_list().


Array[Dictionary] get_script_property_list() 🔗

Returns the list of properties in this Script.

Note: The dictionaries returned by this method are formatted identically to those returned by Object.get_property_list().


Array[Dictionary] get_script_signal_list() 🔗

Returns the list of signals defined in this Script.

Note: The dictionaries returned by this method are formatted identically to those returned by Object.get_signal_list().


bool has_script_method(method_name: StringName) const 🔗

Returns true if the script, or a base class, defines a method with the given name.


bool has_script_signal(signal_name: StringName) const 🔗

如果腳本或基底類別定義了具有給定名稱的訊號,則返回 true


bool has_source_code() const 🔗

Returns true if the script contains non-empty source code.

Note: If a script does not have source code, this does not mean that it is invalid or unusable. For example, a GDScript that was exported with binary tokenization has no source code, but still behaves as expected and could be instantiated. This can be checked with can_instantiate().


bool instance_has(base_object: Object) const 🔗

已棄用: Compare this script with Object.get_script() instead.

如果 base_object 是該腳本的實例,則返回 true


bool is_abstract() const 🔗

如果腳本是工具腳本,則返回 true。工具腳本可以在編輯器中運作。


bool is_tool() const 🔗

如果腳本是工具腳本,則返回 true。工具腳本可以在編輯器中運作。


Error reload(keep_state: bool = false) 🔗

重新載入腳本的類的實作。返回一個錯誤程式碼。