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 Visual Basic syntactic tradition, 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"]) }
[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) } [See the original version] >3. Simple Click response: on noticeClick { Say("Ow!") }
[See the original version] >4. The next generation Click response. Play a random gesture. on noticeClick { PlayGesture(RandomElement(gestures)) } Where RandomElement could be defined by: def RandomElement := to (collection) { def elements := collection indexable elements[elements size random] }
[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!") } [See the original version] >6. A ridiculously simple Eliza: on noticeSpeech(avatar, text) { Say("That's interesting " + avatar name + ". Tell me more about " + text) }
[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) } }
[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)) } 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 {} } 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.
|