Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

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_instance_base_type ( ) const

Variant

get_property_default_value ( StringName property )

Dictionary

get_script_constant_map ( )

Dictionary[]

get_script_method_list ( )

Dictionary[]

get_script_property_list ( )

Dictionary[]

get_script_signal_list ( )

bool

has_script_signal ( StringName signal_name ) const

bool

has_source_code ( ) const

bool

instance_has ( Object base_object ) const

bool

is_abstract ( ) const

bool

is_tool ( ) const

Error

reload ( bool keep_state=false )


属性说明

String source_code

  • void set_source_code ( String value )

  • String get_source_code ( )

脚本的源代码,如果源代码不可用,则为空字符串。当设置时,不会自动重新加载类的实现。


方法说明

bool can_instantiate ( ) const

如果该脚本可以被实例化,则返回 true


Script get_base_script ( ) const

返回由该脚本直接继承的脚本。


StringName get_instance_base_type ( ) const

返回脚本的基类类型。


Variant get_property_default_value ( StringName property )

返回指定属性的默认值。


Dictionary get_script_constant_map ( )

返回一个包含常量名称及其值的字典。


Dictionary[] get_script_method_list ( )

返回此 Script 中的方法列表。


Dictionary[] get_script_property_list ( )

返回此 Script 中的属性列表。


Dictionary[] get_script_signal_list ( )

返回在此 Script 中定义的用户信号列表。


bool has_script_signal ( StringName signal_name ) const

如果脚本或基类定义了具有给定名称的信号,则返回 true


bool has_source_code ( ) const

如果脚本包含非空源代码,则返回 true


bool instance_has ( Object base_object ) const

如果 base_object 是该脚本的实例,则返回 true


bool is_abstract ( ) const

如果脚本是抽象脚本,则返回 true。抽象脚本没有构造函数,无法被实例化。


bool is_tool ( ) const

如果脚本是工具脚本,则返回 true。工具脚本可以在编辑器中运行。


Error reload ( bool keep_state=false )

重新加载脚本的类的实现。返回一个错误代码。