Remark on the example

@valentin I found some errors in the example code on the website.

Missing “;”:

var sliderValue = 0
var sliderPrevValue = 0

You should check for undefined in the if because the read function might return 0 which is a legit value. But 0 resolves to false, so the code in the if won’t be executed. Just took me two hours to figure that out. I have a switch which is 0 when it’s turned off and should be turned on in that case, but the code in the if just wouldn’t get executed.

So instead of:

obj.object.on("object", function (msg) {
        var data = JSON.parse(msg)
        if (obj.read("led", data)) {
            slider.value = obj.read("led", data) * 255;
        }
    });

it should be:

obj.object.on("object", function (msg) {
        var data = JSON.parse(msg)
        if (obj.read("led", data) != undefined) {
            slider.value = obj.read("led", data) * 255;
        }
    });

I have changed it. On the webpage and in the downloadable example.

I also added in line 98 of the default object.js a return of undefined if there is no match.

I’m afraid you forgot to add the missing semicolons :wink:

var sliderValue = 0
var sliderPrevValue = 0

Ok, that’s clearer with the explicit return. If nothing is returned javascript defaults to undefined but I think it’s better to explicitly return something.

Oh. Its changed now.

Yes I thought so to.
If I would have explicit return undefined in the first place, I would probably have tested against this return. That kind of thinking would have saved your debugging.