I don't think there's very much information out there about RBScript, so here's a little gem that I worked out for myself today on a whim. Someone pointed out on the forums that Events appeared to have the same syntax as a method declaration does, and I was pointing out that the IDE was just trying to abstract some details away from the user to be "helpful." Really, events do have a different syntax to them. To demonstrate, I whipped up a quick RBScript that shows the true REALbasic syntax.
Note: I find that when I want to throw together an RBScript to demonstrate something, I tend to use the IDE Scripting window to do so. It makes for a perfect RBScript test bed because it does everything for me, and it has a handy code editor to boot (though, there are plenty of annoyances!).
Class Foobar
Protected Event Blah( s as String )
Protected Sub Yippee( s as String )
Blah( s )
End Sub
End Class
Class Wahoo
Inherits Foobar
Sub Yay( s as String )
Yippee( s )
End Sub
Private Sub Blah( s as String ) Handles Event
Print( s )
End Sub
End Class
dim foo as Wahoo
foo = new Wahoo
foo.Yay( "This is a test" )
Now, this is a very contrived example, but it should demonstrate two key points in RBScript. The first is how to properly inherit one class from another. In that case, the Inherits line goes below the class declaration line. If you were to implement interfaces, that would go on its own line as well. The second point is how to delcare and implement events. You declare an event using the Event keyword (and note that all events should be protected in scope because the only thing that can implement an event is a subclass). To implement the event in a subclass, you have to specifically say "Handles Event" at the end of the declaration. (also note that this should be a private method by tradition). That's all there is to it!
OK, I'll bite.
Why would one want to use this?
For the same reason one would want to use events in REALbasic projects. It's just showing you how to do it in RBScript instead of REALbasic code itself.
Lets say you want RBScript to respond to events generated within REALbasic. Is it a matter of writing an RBScript that runs and terminates each time an event occurs, or is there a way for RBScript to "listen" for events?
RBScript is separated from the rest of a REALbasic application via a "sandbox", so there is no way for it to get access to events in REALbasic code (even if they are event definitions on the context object). You'll have to manually fire your RBScripts from the event instead.