Jump to content

[LE] scripting: Objectreference OnUpdate never triggered


darzdarz1

Recommended Posts

I am just started scripting but nothing works as it should: I would like to add a script to an armor that repeatedly checks several conditions and does some action (similar to Dynamic outfits).

 

Here`s my code:

 

scriptName MVCIndoorScript extends ObjectReference
Actor npc_actor

Event OnUpdate()
debug.MessageBox("updatingEvent" )
endEvent

Event OnEquipped(Actor akTarget)
npc_actor = akTarget
RegisterUpdates()
Debug.TraceAndBox("ONEquipped used" + akTarget)
endEvent
Function RegisterUpdates()
Debug.TraceAndBox("Registering for updates")
self.RegisterForUpdate(1.0)
Endfunction
Event OnUnequipped(Actor AkActor)
UnregisterForUpdate()
endEvent

 

When I equip the armor to the player, I get the "Registering for updates" and the "OnEquipped used" messages, but I never get the "updatingEvent" message. What`s wrong (I also tried function OnUpdate() instead of Event but it doesn't work either?

Link to comment
Share on other sites

MVCArmorScript

 

Scriptname MVCArmorScript extends ObjectReference
; https://forums.nexusmods.com/index.php?/topic/7147971-scripting-objectreference-onupdate-never-triggered/

  Actor npc_actor


; -- EVENTs --

EVENT OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
IF (akNewContainer == Game.GetPlayer() as ObjectReference)
ELSE
;;;    UnRegisterForUpdate()
    gotoState("")                    ; ### STATE ###
    RETURN    ; - STOP -    not the player
ENDIF
;---------------------
    gotoState("Waiting")            ; ### STATE ###
    npc_actor = akNewContainer as Actor
    myF_Trace("event_OnContainerChanged")
ENDEVENT


;===================================
state Waiting  ; equip only for player
;============
EVENT OnEquipped(Actor akActor)
    myF_Trace("event_OnEquipped")
    myF_Register()
ENDEVENT

EVENT OnUnEquipped(Actor akActor)
    myF_Trace("event_OnUnEquipped")
    UnRegisterForUpdate()
ENDEVENT

EVENT OnUpdate()
IF self.GetBaseObject()                ; make sure script is valid
ELSE
    gotoState("")                    ; ### STATE ###
    RETURN    ; - STOP -
ENDIF
;---------------------
; repeatedly checks several conditions and does some action
;    here

    myF_Register()
ENDEVENT
;=======
endState


; -- FUNCTIONs -- 2

;---------------------------
FUNCTION myF_Trace(String s)
;---------------------------
    Debug.TraceAndBox(s)
ENDFUNCTION


;----------------------
FUNCTION myF_Register()
;----------------------
    myF_Trace("Registering for updates")

; https://www.creationkit.com/index.php?title=RegisterForSingleUpdate_-_Form
    RegisterForSingleUpdate(1.0)
ENDFUNCTION

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...