MixinScript¶
Inherits: Script < Resource < Reference < Object
Experimental! A script which combines several other Script resources to extend object’s run-time functionality.
Description¶
MixinScript
is a Script which allows to simulate a new class by fusing other Script resources into one. MixinScript
is a cross-language implementation of the Mixin programming concept.
All objects that use MixinScript
can have properties, methods and signals to be available in the same instance.
Mixin scripts are added either via editor or code using add_mixin. All mixin scripts added to MixinScript
must inherit from Mixin class. MixinScript
use internal Mixin instances to extend the behavior of the owner. You can treat Mixin objects as if they were the owners themselves, since all properties, methods and signals are going to be available in the owner at run-time, and are allowed to override virtual methods such as Node._ready, even if they don’t exist in the Mixin class. But do note that some languages like GDScript won’t be able to provide features like autocompletion, because in most cases, Mixin class may not represent the owner’s real base class.
If scripts share the same properties, methods or signals, only the first occurrence of those will be used throughout scripts. This means that name conflict resolution is implicit, so you may want to change the order of mixin scripts via editor or using move_mixin method at run-time.
Depending on the language, properties, methods and signals may not be directly available in the Mixin classes, but an instance of the class. Due to the nature of cross-language implementation, those languages might not be aware of the mixin mechanism used by MixinScript
, leading to parse errors as seen in GDScript.
Methods¶
void | add_mixin ( Script script ) |
void | clear_mixins ( ) |
Script | get_mixin ( int index ) const |
int | get_mixin_count ( ) const |
void | insert_mixin ( int position, Script script ) |
void | move_mixin ( int position, Script script ) |
void | remove_mixin ( int index ) |
void | set_mixin ( int index, Script script ) |
Property Descriptions¶
- Array mixins
Default | [ ] |
Setter | set_mixins(value) |
Getter | get_mixins() |
An array of all Script mixins used by this script.
Method Descriptions¶
- void add_mixin ( Script script )
Adds a new script to extend the behavior of the owner.
- void clear_mixins ( )
Removes all mixins from this script.
Returns a script at index previously added with add_mixin.
- int get_mixin_count ( ) const
Returns the total number of scripts in MixinScript
.
Inserts a new script at a given position in the array of mixins. The behavior is equivalent to Array.insert.
Moves an existing script to a different position (order) among the other scripts. Since calls, signals, etc are performed in script order, changing the order of scripts may be necessary.
- void remove_mixin ( int index )
Removes an existing script at index. The functionality of the old script will no longer be available in the instance that uses MixinScript
.
Changes the script at index. The functionality of the old script will no longer be available in the instance that uses MixinScript
.