It seems like a common problem creators run into while learning Verse is trying to pass in additional parameters while subscribing events to functions. For example, if you have multiple buttons that you want to print a different color based on a string parameter, you might try subscribing the InteractedWithEvent to a function like PrintColor(Color : string). This would cause an error, because (generally) by default all events can only be subscribed to a function with an agent parameter. The solution to this is a handler function.
Handler functions are essentially a way of passing additional parameters by creating a class object and calling a function using the class attributes. Here is a copy-paste format for how to use them:
Paste this at the very top of your code (or above your main class):
Handler1 := class() {
Device : main <#YOU MUST CHANGE "main" TO YOUR VERSE DEVICE NAME#>
Parameter1 : int <#Change "int" to your parameter type, ex: float, string#>
HandlerFunction(Agent : agent) : void = {
Device.MainFunction(Parameter1)
}
}
Paste this into your OnBegin. You will need to change the Button.InteractedWithEvent to whatever event you are subscribing with. You will also need to change Value to whatever value you want passed through the parameter:
Button.InteractedWithEvent.Subscribe(Handler1{Device:=Self, Parameter1:=Value}.HandlerFunction)
Finally, create your main function (inside main class but outside of OnBegin):
MainFunction(Parameter1 : int) : void = {
Print("{Parameter1}") #Function code here
}
The uses of handlers may not seem immediately obvious, but they can be very useful when you have multiple devices with the same functionality but different inputs, like if you had an array of buttons each designated to increase the score of a different score manager. I hope this was helpful and good luck!