Jump to content

Yet Another WTF Moment


niston

Recommended Posts

So I have

 

 

Scriptname MyScript extends ObjectReference
 
CustomEvent MyEvent
 
; rest of the script

 

This is attached to some furniture.

 

Attached to the same furniture, there is MyOtherScript, where I have:

 

 

MyScript refMyScript = none
 
Event OnInit()
    refMyScript = ((Self as BaseClass) as ObjectReference) as MyScript
    ; various code ommitted
    RegisterForRemoteEvent(refMyScript, "MyEvent")  ; this is line #117
EndEvent
 
; more code here
 
MyScript.MyEvent(ObjectReference akSender, Bool bSomeParameter) ; this is line #154
   ; some code here
EndEvent

 

Yet.....

 

 

 

Papyrus Compiler Version 2.8.0.4 for Fallout 4
Copyright © ZeniMax Media. All rights reserved.
Starting 1 compile threads for 1 files...
Compiling "MyOtherScript.psc"...
...Blahblah\MyScript.psc(117,44): MyEvent is not an event on MyScript or one if its parents
...Blahblah\MyScript.psc(154,0): MyScript.MyEvent does not exist because MyScript cannot generate MyEvent events
No output generated for MyOtherScript.psc, compilation failed.
Batch compile of 1 files finished. 0 succeeded, 1 failed.
Failed on MyOtherScript.psc

 

 

 

I find myself staring at these error messages in utter disbelief, like, "uhhhhhhh.... wut?"

 

Very clearly, the type of refMyScript is MyScript.

 

And MyEvent is declared at the very top of MyScript. Indeed it is. MyScript wouldn't even compile if it weren't - I checked, just to make 100% sure.

 

So what in the bloody hell of eternal doom is the compiler yapping about MyEvent not being an event on MyScript....? :pinch:

 

I worked around by using a function instead of the event. Still, I'd like to know:

 

WTF? What kind of blasphemy is this?! :ermm: Is my compiler possessed? :devil:

 

 

Link to comment
Share on other sites

MyScript refMyScript = none
 
Event OnInit()
    refMyScript = (Self as ObjectReference) as MyScript
    ; various code ommitted
    RegisterForCustomEvent(refMyScript, "MyEvent")  ; this is line #117
EndEvent
 
; more code here
 
Event MyScript.MyEvent(MyScript akSender, Var[] akArgs) ; this is line #154
   ; some code here
EndEvent

akArgs are defined in MyScript when you send the custom event (SendCustomEvent)

Link to comment
Share on other sites

If, like me, you are confused by swords and dragons in the unclear CK examples, always search your ...\Data\Scripts\Source\Base scripts for examples in context:

 

The ever useful WorkshopParentScript both defines a custom event:

CustomEvent WorkshopInitializeLocation

 

and then registers for its own event:

Self.RegisterForCustomEvent(Self, "WorkshopInitializeLocation")

 

and then sends it:

SendCustomEvent("WorkshopInitializeLocation")

 

and then receives it:

Event WorkshopParentScript.WorkshopInitializeLocation(WorkshopParentScript akSender, Var[] akArgs)

Edited by SKK50
Link to comment
Share on other sites

RegisterForCustomEvent seems to work.

 

Fun is, I've already used both Custom and Remote in my own scripts, but still got a confuzzle at times.

 

Sooo.... As a general rule of thumb: If the two scripts are attached to the same object, RegisterForCustomEvent is used and if they are attached to two different objects, Register ForRemoteEvent is used?

Edited by niston
Link to comment
Share on other sites

If you are working with a custom event then use RegisterForCustomEvent, otherwise use RegisterForRemoteEvent.

You don't need to use RegisterForRemoteEvent when the event is being received from the Actor/ObjectReference where the script is attached, but if you are sending a custom event you always need register for it, it doesn't matter if is the same script or another script, or if it is in the same object or another object or form.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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