Talk:Custom Papyrus Events

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search


Handling Arguments[edit source]

So when your handling an event on a script that has registered for an event with a 'host?' script Ive noticed there may be a lot of validation for the arguments. Would it be outside the 'host' scripts responsibility to validate the event arguments it sends? Im trying this code in which the host provides a bool function which returns true is the Var[] arguments are of the expected length and type. I would like opinion on this from other scripters. --Scrivener07 (talk) 2016-05-31T20:40:48 (EDT)

; client script

Event AmbushTriggerScript.Ambush(AmbushTriggerScript akSender, Var[] arguments)
  Debug.Trace("Got Ambush event for " + akSender + " with arguments: " + arguments)
	If(akSender.IsAmbushEvent(arguments))
		Actor kActor = arguments[0] as Actor
		float fDelay = arguments[1] as float
		Log("We are targeting: " + kActor + " after " + fDelay + " seconds")
	EndIf
EndEvent


; host AmbushTriggerScript

bool Function IsAmbushEvent(Var[] arguments)
	return (arguments.Length == 2 && arguments[0] is Actor && arguments[1] is float)
EndFunction

I proceed like this in C++, so it sounds a good idea --Toxicat (talk) 2016-05-31T14:44:54 (EDT)