Sign In Register

How can we help you today?

Start a new topic
Answered

Event creation and Boolean type

Hello,


When creating an event I have the option to add attributes with a data type of String, Number or JSON but not Bool.


My question:  why this is? And is anyone is dealing with this in a better way than I am?


My workaround is to create my event and give it an attribute with a number or a string datatype and in my cloud code I return it as a variable.


Something like this:

if (worldTS == gsWorldTS)
    {
        var tsBoolean = "1"; // true
    }
else
    {
        var tsBoolean = "0"; // false
    }
// Return the boolean to the device   
Spark.setScriptData("tsBoolean", tsBoolean);

Thanks,

Maria


Best Answer

Hi Maria,


If you change the attribute to JSON you can have Booleans, the method you are using at present will work but is slightly more costly in terms of memory.


A quick example using a JSON attribute: 


if (worldTS == gsWorldTS)

{

    var tsBoolean = true;

}

else

{

    var tsBoolean = false;


Spark.setScriptData("tsBoolean", tsBoolean);    // If you test this via the test harness, just remove the curly brackets before entering a boolean value


Hope this helps,

- Tony



Answer

Hi Maria,


If you change the attribute to JSON you can have Booleans, the method you are using at present will work but is slightly more costly in terms of memory.


A quick example using a JSON attribute: 


if (worldTS == gsWorldTS)

{

    var tsBoolean = true;

}

else

{

    var tsBoolean = false;


Spark.setScriptData("tsBoolean", tsBoolean);    // If you test this via the test harness, just remove the curly brackets before entering a boolean value


Hope this helps,

- Tony


Brilliant Tony, I will try this out!


Thank you,

Maria

Login to post a comment