ERights Home e 
Back to: World Scripting in VB On to: Satan Comes to Dinner in E

E World Scripting Examples
in the Visual Basic syntactic tradition
(from a correspondence with Tony Grant, archived on ec_ez)


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 Interface

Standard 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
>and forth between CentralPark region and BeachResort.
>
>This would help us to find any memory leaks occurring on transitions. I
>don't know how much overhead would be involved in this, but it would be
>great if it were simple:

    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
>new art checking to make sure that none of the new regions have broken the
>world.

    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
>or her:

    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)

I'm not sure what you intended by saying "no error checking". If you want to code in ignorance of the issue of errors, uncaught errors will terminate your loop:

    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 Enhancements

E 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.

  • When object A invokes object B, usually it is to serve a purpose of A's, and the invocation can be seen as an imperative or query. The invocation is assumed to be on the caller's behalf. For this case the "To" form is used to define the corresponding method, as in "To verb(arg, ...)", and invocation can be either a synchronous call or an asynchronous send ("<-"). A synchronous call is a sensible possibility since A is subcontracting to B, and B's effects are typically part of the effects A is trying to bring about. Since the invocation is assumed to be on A's behalf, a to-invocation has an implicit return value, which is a Promise in the asynchronous case.

  • The other common purpose for an invocation is event notification (called by various o-o commentators Observers, Dependents, Reactors, ...). Typically, object B will have earlier registered with A an interest in certain kinds of events. Later, when A decides that these events have occurred, it informs all interested parties, like B, by invoking them. These invocations are assumed to be on the callee's behalf. The method would be defined as "On eventName(arg, ...)", and the corresponding invocation could only be asynchronous ("<-"), since B's reactions to the event (and any consequent side effects) are not properly part of the action A was in the midst of. By the same token, A is assumed not to be interested in any results or exceptions from B, so no implicit return value is supplied.

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.
ERights Home e 
Back to: World Scripting in VB On to: Satan Comes to Dinner in E
Download    FAQ    API    Mail Archive    Donate

report bug (including invalid html)

Golden Key Campaign Blue Ribbon Campaign