Skip to content

observer_template

Kamran Wali edited this page Dec 1, 2024 · 2 revisions

Inherits: Resource

Resource template script for creating new observer types.

Description

observer_template is a Resource template script. You can use this template script to create new scripts/objects that will act as an observer. These scripts basically stores and shares the reference to a value. Also when the value has been changed then the changed value will also be emitted to its observers through the callables in the Singal. This class works as the Observer Pattern. The value can NOT be set during editor mode but it can ONLY be set during run time. Example of observers scripts are cop_observer_bool, cop_observer_float and cop_observer_int.

Note: Make sure to give a unique class name for the new script so that you can create it in the editor.

Tutorial

Properties

Type Name Default Value
untype _value

Methods

Return Type Name
untype get_value()
untype get_value_emit()
void set_value( untype value )
void set_value_emit( untype value )
void disconnect_all()

Signals

value_changed ( untype value )

Emitted when the _value has been changed through the method set_value_emit(). The parameter for the signal is untype. So make sure to give the type of the value parameter same as the property _value type. If NOT then every time this signal is emitted it will then throw an error.


Property Descriptions

untype _value

The stored value that will be sent to observers when ever this value changes through the method set_value_emit(). This value is also emitted to observers when the method get_value_emit() is called. You can also get/set the value without the need for emitting by calling the methods get_value() or set_value() respectively. Note: This property is untype so make sure to set the type for the property.


Method Descriptions

untype get_value ()

This method returns the _value without emitting to the observers. The return type is untype. So make sure to give the return type same as the _value's type. If NOT done so then this script will throw errors whenever this method is called.


untype get_value_emit ()

This method returns the _value and emits it to the observers. The return type is untype. So make sure to give the return type same as the _value's type. If NOT done so then this script will throw errors whenever this method is called.


void set_value ( untype value )

This method sets the _value without emitting to the observers. The parameter value is untype. So make sure the type of this parameter is same as the _value's type. If NOT then this method will throw errors whenever it is called.


void set_value_emit ( untype value )

This method sets the _value and emits it to the observers. The parameter value is untype. So make sure the type of this parameter is same as the _value's type. If NOT then this method will throw errors whenever it is called.


void disconnect_all ()

This method removes/disconnects all the connected callable objects from the Signal value_changed.


Clone this wiki locally