This document presents examples in E for scripting behaviors in our virtual worlds. Tony started things off with examples showing how our worlds might be made easily scriptable for the Visual Basic programmer. After some (archived) iterations, here is my best take on doing Tony's examples within all our foundational constraints--including capability secure programming--in the E language. The examples use E as it works today except for two enhancements noted below. Here is Tony's original message. The examples in this document and Tony's message are now cross-linked to each other so you can easily see how the examples compare. IMO, the results compare well with the imagined Visual Basic code. For those more comfortable with the C syntactic tradition (spanning at least C, C++, Java, Perl, Python, Tcl, and csh), here is a version of this document you may like better. The E language accepts both styles. However, I'm almost totally ignorant of Pluribus and of the internals of the cosm level of our system, so the interface to it presented here may be wholly unrealistic. Cosm/Unum programmers: How reasonable are our assumptions? How reasonable are our examples?
[See the original version] Hypothetical Unum/Puppet/Cosm InterfaceStandard events: noticeClick noticeBump(other) noticeRegionEntry(avatar) noticeRegionExit(avatar) noticeSpeech(avatar, text) "other" and "avatar" above would probably be some appropriate level of puppet, but none of this has been revisited since the puppet revolution. Suggestions and clarifications would be most appreciated! "Instance" Variables: myName myPossessions myOwner myRegion myBody "Global" Name Spaces: bodies regions gestures "Global" Functions: PlayGesture(gesture) Say(text) TestLaunch(avatarBody, region) WalkTo(region) TeleportTo(region) RandomElement(collection) (I need to understand more about portals & teleport pads)
[See the original version] >1. Launch Microcosm with Yappy as the avatar and have him transition
back TestLaunch(bodies["Yappy"], regions["CentralPark"]) For i In (1..100) TeleportTo(regions["BeachResort"]) TeleportTo(regions["CentralPark"]) End For
[See the original version] >2. Visit every region in a realm. This would a great script to run
after TestLaunch(bodies["Dax"], regions["CentralPark"]) For r In (myRegion realm regions) TeleportTo(r) End For
[See the original version] >3. Simple Click response: On noticeClick Say("Ow!") End On
[See the original version] >4. The next generation Click response. Play a random gesture. On noticeClick PlayGesture(RandomElement(gestures)) End On Where RandomElement could be defined by: Define RandomElement := To (collection) Define elements := collection indexable elements[elements size random] End To
[See the original version] >5. A greeting bot. When an avatar enters the region, the bot welcomes
him On noticeRegionEntry(avatar) Say("Hi " + avatar name + ". Welcome to KidsWorld!") End On
[See the original version] >6. A ridiculously simple Eliza: On noticeSpeech(avatar, text) Say("That's interesting " + avatar name + ". Tell me more about " + text) End On
[See the original version] >7. Have a bot in your Turf that reacts to the mention of your name. On noticeSpeech(avatar, text) If (text includes(myOwner name)) PlayGesture(gestures["Spin"]) Say("I sure do love " + myOwner name) End If End On
[See the original version] >8. The wandering avatar: (no error checking for a region with no
portals) TestLaunch(bodies["Dax"], regions["CentralPark"]) For i In (1..100) WalkTo(RandomElement(regions)) End For The first WalkTo that throws an error will exit this loop. Alternatively, if you want to ignore errors and keep going: TestLaunch(bodies["Dax"], regions["CentralPark"]) For i In (1..100) Try WalkTo(RandomElement(regions)) Catch End Try End For try/catch is how you handle errors. The empty curlies after the 'catch' say to do nothing on an error. Assumed E EnhancementsE has already reserved the "On" keyword. This document assumes that the "On" keyword has been added to the language in a role similar to the existing "To" keyword. The difference between "On" and "To" reflect two very different purposes for invocation (calling/sending) in object oriented programming.
As Hypercard has shown, the event driven model is quite pleasant. Unlike Smalltalk, Hypercard does not make an object register in order to receive notifications of events it's interested in. It suffices to have (the equivalent of) an on-method for that event, and to be in a context in which these events are ambient. For our worlds, the Frame/Session (or maybe the container?) can serve as such a context. [Need to explain group membership] We therefore need a CRAPI-like E meta-protocol so such a context can find out, when an object is added to that context, what on-methods it has. An object can be assumed to be interested in any event it has an On-method for.
|
||||||||||||
Unless stated otherwise, all text on this page which is either unattributed or by Mark S. Miller is hereby placed in the public domain.
|