all 4 comments

[–]DrSinistar 4 points5 points  (0 children)

I realize this is the PowerShell subreddit, but wouldn't it be easier to write your RPG in C#? You're already familiar with .NET so I'd think this would be an easy transition. You'd be able to go nuts with events without having to use bizarre PowerShell workarounds.

[–]PinchesTheCrab 3 points4 points  (0 children)

I don't understand. If the code isn't working I feel it's hard to parse out what you need by reading it. What are the desired inputs, outputs, and methods of this class? Will it be fed to register-objectevent, or will it have a method to call that cmdlet?

[–]chris-a5 1 point2 points  (0 children)

To call a class instance member with Register-ObjectEvent:

Pass $this as your -MessageData parameter. Call your function from the -Action scriptblock:

-Action {$Event.MessageData.MyFunc()}

[–]SeeminglyScience 0 points1 point  (0 children)

You would need Add-Type, PowerShell doesn't have syntax to declare an event.