Difference between revisions of "RegisterForModEvent - Form"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Jbezorg
(Created page with "Registers a custom event callback for given event name. Registrations have to be refreshed after each game load. Examples: RegisterForModEvent("myCustomEvent", "MyModEventC...")
 
imported>Pickysaurus
m (Added note for citation of my update)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Category:Scripting]]
[[Category:Papyrus]]
[[Category:SKSE]]
'''SKSE Member of:''' [[ActiveMagicEffect Script]], [[Alias Script]], and [[Form Script]]
Registers a custom event callback for given event name.
Registers a custom event callback for given event name.
Registrations have to be refreshed after each game load.
Registrations have to be refreshed after each game load.


Examples:
== Syntax ==
  RegisterForModEvent("myCustomEvent", "MyModEventCallback")
<source lang="papyrus">
Function RegisterForModEvent(string eventName, string callbackName) native
 
;The event:
Event callbackName(string eventName, string strArg, float numArg, Form sender)
EndEvent
</source>
 
== Parameters ==
*eventName: The name of the event sent by [[SendModEvent]].
 
*callbackName: The name by which you can catch the event.
 
== Examples ==
<source lang="papyrus">
; Register to receive the ModEvent:
; named HectorHitMe with the callback of OnHectorHitMe
RegisterForModEvent("HectorHitMe", "OnHectorHitMe")
 
Event OnHectorHitMe(string eventName, string strArg, float numArg, Form sender)
;Do something
EndEvent
</source>
 
== Notes ==
*Aliases and quests will automatically unregister for this event when the quest stops. Active magic effects will automatically unregister when they are removed.
*ModEvent registrations are persistent and are stored in the MCBR record of the SKSE co-save. If you mod relies on these registrations being persistent it is '''strongly''' recommended that you register for the event again after each game load, if the user deletes this file for any reason it could break your mod.<sup>[1]</sup>
 
== References ==
# [https://discordapp.com/channels/115334762415128585/316278100528857088/716726335372001391 Expired, xSE Discord, 31-05-2020].


Event signature of custom event callbacks:
== See Also ==
  Event MyModEventCallback(string eventName, string strArg, float numArg, Form sender)
*[[ActiveMagicEffect Script]]
  endEvent
*[[Alias Script]]
*[[Form Script]]
*[[SendModEvent]]

Latest revision as of 14:36, 31 May 2020

SKSE Member of: ActiveMagicEffect Script, Alias Script, and Form Script

Registers a custom event callback for given event name. Registrations have to be refreshed after each game load.

Syntax[edit | edit source]

Function RegisterForModEvent(string eventName, string callbackName) native

;The event:
Event callbackName(string eventName, string strArg, float numArg, Form sender)
EndEvent

Parameters[edit | edit source]

  • callbackName: The name by which you can catch the event.

Examples[edit | edit source]

; Register to receive the ModEvent:
; named HectorHitMe with the callback of OnHectorHitMe
RegisterForModEvent("HectorHitMe", "OnHectorHitMe")

Event OnHectorHitMe(string eventName, string strArg, float numArg, Form sender)
;Do something
EndEvent

Notes[edit | edit source]

  • Aliases and quests will automatically unregister for this event when the quest stops. Active magic effects will automatically unregister when they are removed.
  • ModEvent registrations are persistent and are stored in the MCBR record of the SKSE co-save. If you mod relies on these registrations being persistent it is strongly recommended that you register for the event again after each game load, if the user deletes this file for any reason it could break your mod.[1]

References[edit | edit source]

  1. Expired, xSE Discord, 31-05-2020.

See Also[edit | edit source]