Login

holosItemInstance

So, you've developed a card, but quickly realized that users can do this:

Lots o' Cards

They can make as many copies of your card as they as they like, simply by pulling them into their space. This means that there can be multiple instances (or copies) of your card in the homespace at once. Having each and every copy show exactly the same content would be pretty boring, so we provide a way for you to figure out which instance of a card your scripts are being run within. Cards no longer have an identity crisis and can declare their individuality to you as a developer.

Let's take a moment to talk about loading. When developing for Holos, loading is a two-stage process. The first one is exactly like you'd expect in a normal web-dev context. The browser instance loads your page, the scripts get loaded, etc., but, then, when the browser reports that the page has finished loading, Holos will initialize a post-launch pass. This post-launch pass will push a series of initial state variables to the browser instance running your card, registering all of the Holos API callbacks, including a method called HolosInit(). If it is available, it will be executed.

You can implement HolosInit() however and wherever you like, but this is where should initialize any code that you're going to use to interact with Holos. The instance ID example card implements the following HolosInit() function:

function HolosInit()
{
    var itemInstanceIDIsDeclared = true;
    try
    {
        holosItemInstance;
    }
    catch (e)
    {
        if(e.name == "ReferenceError")
        {
            itemInstanceIDIsDeclared = false;
        }
    }

    if(itemInstanceIDIsDeclared) { document.getElementById("cardInstanceText").innerHTML = holosItemInstance; }
    else { document.getElementById("cardInstanceText").innerHTML = "No card instance ID found."; }
}

This code first uses a try/catch to safely detect if the variable has been provided by Holos. If so, it uses that value to write to the card face!

Check out the interactive example on CodePen.

Still need help? Get in touch!
Last updated on 19th Jul 2017