Anyland Webpage Commands

You can have your own webpage's JavaScript communicate with Anyland. You can both send messages, as well as receive them. There's also a command to close the page.

Messages from Webpage → Anyland

You can pass messages from the page into Anyland via

AnylandTell("some string");
AnylandTellAny("some string");

// Or better guarded, use e.g.:
if (window.AnylandTell) {
    AnylandTell("some string");
}

 

Then inside Anyland, receive the "some string" data via the usual

When told some string then ...
When told by any some string then ...

"When told" receives from "AnylandTell", but requires the sender and receiver to be within the same Thing creation. "When told by any" receives from "AnylandTellAny", and allows the sending and receiving Things to be different ones, messaging all across the area.

You can also set the currently edited Thing Json via (if one isn't already in Create Thing mode, it will automatically start a new creation):

var json = '{"n":"cyan purple x","p":[{"b":3,"s":[{"p":[0.5,0,0],"r":[45,0,0],' +
        '"s":[0.1,0.8,0.1],"c":[0,1,1]}]},{"b":3,"s":[{"p":[0.5,0,0],"r":[-45,0,0],' +
        '"s":[0.1,0.8,0.1],"c":[1,0,1]}]}]}';

AnylandSetThing(json);

You can also read the currently edited creation Json via this – together with the AnylandSetThing method, this allows you to dynamically change things (note you'll receive an empty string if the user isn't in edit mode):

AnylandRequestThing(); // This calls AnylandGetThing

function AnylandGetThing(json) {
    alert("Json received: " + json);
}

Combining Get & Set lets you modify creations. This one turns all spheres in the creation green and shrinks them (for the full code, see this page's HTML/ JS source):

function ColorAndShrinkSpheres(json) {
    var data = JSON.parse(json);
    for (var partI = 0; partI < data.p.length; partI++) {
        var part = data.p[partI];
        var baseType = part.b;
        var states = part.s;
                                
        for (var stateI = 0; stateI < states.length; stateI++) {
            var state = states[stateI];

            switch (baseType) {
                case ThingPartBase.Sphere:
                case ThingPartBase.LowPolySphere:
                case ThingPartBase.Icosphere:
                case ThingPartBase.JitterSphere:
                case ThingPartBase.HighPolySphere:
                case ThingPartBase.FineSphere:
                    var factor = 0.5;
                    state.s = [
                        state.s[0] * factor,
                        state.s[1] * factor,
                        state.s[2] * factor
                    ];
                    state.c = [0.0, 1.0, 0.0];
                    break;
            }

        }
    }

    var jsonNew = JSON.stringify(data);
    console.log(jsonNew);
    if (window.AnylandSetThing) {
        AnylandSetThing(jsonNew);
    }
}

You can also have the browser emit an Anyland Thing. First, copy the Thing Id by context-lasering a placement, clicking "Copy & Paste" on the Thing Dialog's backside, then clicking Thing Id - "Copy". Paste the id into the function like below:

AnylandEmitThing("5ca6043a567df515eb5ec79f");

 

Messages from Anyland → Webpage

Reversely, the webpage can receive tells. Send them from Anyland via

When ... then tell web some string

... and receive them inside the JavaScript via ...

AnylandTold(data, isAuthority);

Note the data parameter (e.g. "some string") arrives in all lower-case. The boolean value "isAuthority" will tell you if the current client is the authoritative client in the area at the moment.

The following gets the currently edited Thing's Json if requested:

AnylandGetThing(json);

More commands

A general command you can use to close the current browser page that was opened in Anyland is

AnylandClosePage();