[Newbie] ERROR: the index 'light_level' does not exist

I am running into a strange problem.

Here is my device codes:

`const DEF_LIGHT_LEVEL = 35000;
const DEF_DOOR_TIME = 10.0;

class GDM {
    light_level = DEF_LIGHT_LEVEL;
    dtime = DEF_DOOR_TIME;

    function set_door_time(value)
    {
        dtime = value;
    }

58:    function set_light_level(value)
59:    {
60:        light_level = value;   <i>// here is the problem line</i>
61:    }

    function get_config(value)
    {
        local mytable = { "light_level" : light_level, "door_time" : dtime};
        return mytable;
    }
}


gdm <- null;
door_state <- null;

gdm = GDM();

if (hardware.lightlevel() < gdm.light_level)
{
    door_state = STATE.CLOSED;
    server.log("CLOSED");
}
else
{
    door_state = STATE.OPEN;
    server.log("OPEN");
}

gdm.set_light_level(30000);`

And the output is:

`2015-05-27 23:26:56 UTC-7	[Status]	Device connected
2015-05-27 23:26:56 UTC-7	[Device]	OPEN
2015-05-27 23:27:08 UTC-7	[Agent]	set light config 34000
2015-05-27 23:27:08 UTC-7	[Device]	ERROR: the index 'light_level' does not exist
2015-05-27 23:27:08 UTC-7	[Device]	ERROR:   at set_light_level:60
2015-05-27 23:27:13 UTC-7	[Status]	Device disconnected`

You can see that I referred to gdm.light_level in the main code and it worked fine till I called gdm.set_light_level(30000).

I have searched around for several hours and change the statements numerous times and nothing improved. Can you kind souls here help me with this?

Best regards,

Jack

I copied + pasted you code (and added STATE.OPEN and STATE.CLOSED to the top) and I’m not getting the error:

`const DEF_LIGHT_LEVEL = 35000;
const DEF_DOOR_TIME = 10.0;

STATE <- {
OPEN = 1,
CLOSED = 0
};

class GDM {
light_level = DEF_LIGHT_LEVEL;
dtime = DEF_DOOR_TIME;

function set_door_time(value)
{
    dtime = value;
}

function set_light_level(value)
{
    light_level = value;
}

function get_config(value)
{
    local mytable = { "light_level" : light_level, "door_time" : dtime};
    return mytable;
}

}

gdm <- null;
door_state <- null;

gdm = GDM();

if (hardware.lightlevel() < gdm.light_level)
{
door_state = STATE.CLOSED;
server.log(“CLOSED”);
}
else
{
door_state = STATE.OPEN;
server.log(“OPEN”);
}

gdm.set_light_level(30000);`

I’m guessing you pulled out some code to simplify the example, and I think your bug exists elsewhere…

Thanks for helping. Yes, I simplified my code. I had enum STATE defined earlier.

One thought: I have gdm.light_level in the main code but not gdm.dtime. In my class declaration, even I change the order of the member functions, the error always is at light_level. Maybe this is the difference, I will test.