Page 1 of 1

Help with 1st variable script

Posted: Tuesday 10 May 2016 20:47
by blackdog65
Hi guys,

I'm trying to write my first variable script for tracking bluetooth beacons.
My variables update fine but I'm trying to get them to toggle some virtual switches... and my script doesn't work.
Please keep it simple as I'm struggling to get a grip on lua :oops:

I know it's a bit clunky but here it is

Code: Select all

-- script_variable_bt.lua
commandArray = {}

for variableName,variableValue in pairs(uservariablechanged) do
    if (variableName=='Zhenya_Kitchen') then
        if variableValue == HOME then
            commandArray['ZKitchenBT'] = "On"
        end
    end
    if (variableName=='Zhenya_Kitchen') then
        if variableValue == AWAY then
            commandArray['ZKitchenBT'] = "Off"
        end
    end

    if (variableName=='Zhenya_Office') then
        if variableValue == HOME then
            commandArray['ZOfficeBT'] = "On"
        end
    end
    if (variableName=='Zhenya_Office') then
        if variableValue == AWAY then
            commandArray['ZOfficeBT'] = "Off"
        end
    end

    if (variableName=='Zhenya_Hall') then
        if variableValue == HOME then
            commandArray['ZHallBT'] = "On"
        end
    end
    if (variableName=='Zhenya_Hall') then
        if variableValue == AWAY then
            commandArray['ZHallBT'] = "Off"
        end
    end

    if (variableName=='Zhenya_SitRm') then
        if variableValue == HOME then
            commandArray['ZSitRoomBT'] = "On"
        end
    end
    if (variableName=='Zhenya_SitRm') then
        if variableValue == AWAY then
            commandArray['ZSitRoomBT'] = "Off"
        end
    end


end

return commandArray
Many thanks

Sean

Re: Help with 1st variable script

Posted: Tuesday 10 May 2016 21:10
by jvdz
Sean,

You are getting errors i guess?
Looks line this line:

Code: Select all

if variableValue == HOME then
Should be this :

Code: Select all

if variableValue == "HOME" then
..and the same for the other if statements.

Jos

Re: Help with 1st variable script

Posted: Tuesday 10 May 2016 21:37
by blackdog65
Yay! :D
jvdz wrote:Sean,

You are getting errors i guess?
Looks line this line:

Code: Select all

if variableValue == HOME then
Should be this :

Code: Select all

if variableValue == "HOME" then
..and the same for the other if statements.

Jos
Many Thanks Jos, worked a treat :D