> For the complete documentation index, see [llms.txt](https://wiki.redmodding.org/scripting-cyberpunk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.redmodding.org/scripting-cyberpunk/scripting/game-systems/events-and-callbacks.md).

# Events & Callbacks

## 1. Events Based on Predefined Method Names

To handle the event, you just have to define a function with the right signature and name. It's called by name just like any other function, for example `OnInitialize()` in widget controllers.

## 2. Events Based on Event Classes Inherited From [`redEvent`](https://nativedb.red4ext.com/c/3352609018084022)

To listen for this event, you have to define a function that has the event flag (`cb`) and takes exactly one argument of the reference for the event class, it's auto-wired during scripting runtime initialization and can be triggered using methods like `QueueEvent()`, for example: `protected cb func OnHit(evt: ref<gameHitEvent>) -> Bool` on [`ScriptedPuppet#OnHit`](https://nativedb.red4ext.com/ScriptedPuppet#OnHit).

{% hint style="info" %}
The name of the function doesn't matter in this case, all that's important is the method has the `cb` flag and takes exactly one argument of the event type (this may need to be fact checked).
{% endhint %}

There are two separate contexts where these events can be used:

* widgets (events can be broadcasted)
* entities (events can only be dispatched for one entity at a time, and also reaches its components)

{% content-ref url="/pages/IBQVIkCrA0Kiu6SwfCur" %}
[Custom redEvents](/scripting-cyberpunk/scripting/game-systems/events-and-callbacks/custom-redevents.md)
{% endcontent-ref %}

### 2.1 [`ScriptableSystemRequest`](https://nativedb.red4ext.com/ScriptableSystemRequest)

There's also `gameScriptableSystem` with [`gameScriptableSystemRequest`](https://nativedb.red4ext.com/c/154536877873313) working in a similar way, but there's a hard-coded limit for the number of requests so it's recommended to not create new request types.

## 3. Callback Managers

different types have their own functions to register and unregister listeners the signature of the listener is always fixed, and you have to know it you have to define a listener function and register it providing target object and name of the listener method

for example, blackboards `RegisterListenerBool(id : gamebbScriptID_Bool, object : handle:IScriptable, func : CName, fireIfValueExist : Bool)`

### 3.1. Callback Manager That Requires an Object Implementing Specific Interface, Instead of Just One Function

For example, [`AttachmentSlotsScriptCallback`](https://nativedb.red4ext.com/c/5976827158091819) for slots and [`InventoryScriptCallback`](https://nativedb.red4ext.com/InventoryScriptCallback) for [`TransactionSystem`](https://nativedb.red4ext.com/TransactionSystem).

To register a listener for these types, you instead need to define a class that extends the respective callback and implement the various functions for your use case. When registered, the manager will call the methods when the respective event happens.
