Script

package
v0.0.0-...-535787f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

A class stored as a resource. A script extends the functionality of all objects that instantiate it.

This is the base class for all scripts and should not be used directly. Trying to create a new script with this class will result in an error.

The new method of a script subclass creates a new instance. graphics.gd/classdb/Object.Instance.SetScript extends an existing object, if that object's class matches one of the script's base classes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsScript() Instance
}

type Expanded

type Expanded [1]gdclass.Script

func (Expanded) Reload

func (self Expanded) Reload(keep_state bool) error

Reloads the script's class implementation. Returns an error code.

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

func (*Extension[T]) AsRefCounted

func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted

func (*Extension[T]) AsResource

func (self *Extension[T]) AsResource() Resource.Instance

func (*Extension[T]) AsScript

func (self *Extension[T]) AsScript() Instance

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.Script

Instance of the class with convieniently typed arguments and results.

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func Get

func Get(obj Object.Any) (Instance, bool)

Get returns the object's Script instance, or false if no script is attached.

func New

func New() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (Instance) AsResource

func (self Instance) AsResource() Resource.Instance

func (Instance) AsScript

func (self Instance) AsScript() Instance

func (Instance) CanInstantiate

func (self Instance) CanInstantiate() bool

Returns true if the script can be instantiated.

func (Instance) GetBaseScript

func (self Instance) GetBaseScript() Instance

Returns the script directly inherited by this script.

func (Instance) GetGlobalName

func (self Instance) GetGlobalName() string

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#.

func (Instance) GetInstanceBaseType

func (self Instance) GetInstanceBaseType() string

Returns the script's base type.

func (Instance) GetPropertyDefaultValue

func (self Instance) GetPropertyDefaultValue(property string) any

Returns the default value of the specified property.

func (Instance) GetRpcConfig

func (self Instance) GetRpcConfig() any

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

func (Instance) GetScriptConstantMap

func (self Instance) GetScriptConstantMap() map[string]interface{}

Returns a dictionary containing constant names and their values.

func (Instance) GetScriptMethodList

func (self Instance) GetScriptMethodList() []Object.PropertyInfo

Returns the list of methods in this graphics.gd/classdb/Script.

Note: The dictionaries returned by this method are formatted identically to those returned by graphics.gd/classdb/Object.Instance.GetMethodList.

func (Instance) GetScriptPropertyList

func (self Instance) GetScriptPropertyList() []Object.PropertyInfo

Returns the list of properties in this graphics.gd/classdb/Script.

Note: The dictionaries returned by this method are formatted identically to those returned by graphics.gd/classdb/Object.Instance.GetPropertyList.

func (Instance) GetScriptSignalList

func (self Instance) GetScriptSignalList() []SignalInfo

Returns the list of user signals defined in this graphics.gd/classdb/Script.

Note: The dictionaries returned by this method are formatted identically to those returned by graphics.gd/classdb/Object.Instance.GetSignalList.

func (Instance) HasScriptSignal

func (self Instance) HasScriptSignal(signal_name string) bool

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

func (Instance) HasSourceCode

func (self Instance) HasSourceCode() bool

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 graphics.gd/classdb/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 Instance.CanInstantiate.

func (Instance) ID

func (self Instance) ID() ID

func (Instance) InstanceHas

func (self Instance) InstanceHas(base_object Object.Instance) bool

Returns true if 'base_object' is an instance of this script.

func (Instance) IsAbstract

func (self Instance) IsAbstract() bool

Returns true if the script is an abstract script. An abstract script does not have a constructor and cannot be instantiated.

func (Instance) IsTool

func (self Instance) IsTool() bool

Returns true if the script is a tool script. A tool script can run in the editor.

func (Instance) Reload

func (self Instance) Reload() error

Reloads the script's class implementation. Returns an error code.

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) SetSourceCode

func (self Instance) SetSourceCode(value string)

func (Instance) SourceCode

func (self Instance) SourceCode() string

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type SignalInfo

type SignalInfo struct {
	Name        string                `gd:"name"`
	Flags       int                   `gd:"flags"`
	ID          int                   `gd:"id"`
	DefaultArgs []interface{}         `gd:"default_args"`
	Args        []Object.PropertyInfo `gd:"args"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL