nodecentral
nodecentral

Reputation: 466

Lua - Find value between 1 - 4 , but only return others

I’m not quite sure how to explain this, but I’m trying to find a way to return all the values between 1 to 4 , that are not the value provided.

For example, let say I provide value ‘2’, I want the process to return 1,3,4 for me to process individually.

To give you a more specific explanation, I’m putting together a script to retrieve the input in use against each output of a 4x4 HDMI matrix. I can retrieve the input in use e.g 2, and enable that button on a UI, but I can’t work out to get the other 3 values, to request that those buttons are turned off on the UI too.

Discover what’s on..(value returned 2)

luup.variable_set("urn:upnp-net:serviceId:Matrix1", "input2", ‘true’, 

Turn off the others..

luup.variable_set("urn:upnp-net:serviceId:Matrix1", "input1", ‘false’, 
luup.variable_set("urn:upnp-net:serviceId:Matrix1", "input3", ‘false’, 
luup.variable_set("urn:upnp-net:serviceId:Matrix1", "input4", ‘false’, 

Hope that helps someone to help me ?

Upvotes: 0

Views: 54

Answers (1)

do-no-van
do-no-van

Reputation: 236

function foo(n)
    tbl = {1, 2, 3, 4}
    table.remove(tbl, n)
    return tbl
end

or to also call those functions

function foo(n)
    tbl = {1, 2, 3, 4}
    luup.variable_set("urn:upnp-net:serviceId:Matrix1", "input"..table.remove(tbl, n), ‘true’)
    
    for num, _ in ipairs(tbl) do
        luup.variable_set("urn:upnp-net:serviceId:Matrix1", "input"..num, ‘false’)
    end
end

Upvotes: 1

Related Questions