string and number
Posted: Monday 15 March 2021 12:06
I have a script that retrieves config_data for setting the config a siren or doorbell based on inputs from a slector switch like 'medium', 'hard'
i like to change this script so that the input data can be a selected dim level and then do the same trick by retrieving the data.
In this case there has to be a range check for the corresponding data.
Another issue is that the script must handle strings and numbers and detect how to handle the input variable, string (is value matching), number is range matching.
I made a first test script, and like to have feedback if this is the way to go...
i like to change this script so that the input data can be a selected dim level and then do the same trick by retrieving the data.
In this case there has to be a range check for the corresponding data.
Another issue is that the script must handle strings and numbers and detect how to handle the input variable, string (is value matching), number is range matching.
I made a first test script, and like to have feedback if this is the way to go...
Code: Select all
local volume_states = {
{'uit','Low',0,'Off',0,0,0}, -- p1 = waarde tekst, p2 bel/sirene volume, p3=nodered volume, p4=volumeduur_alarm Off=uit, p5=volumeduur_deurbel 0= uit, p6= range lowondergrens, p7 range volume bovengrens
{'fluister', 'Low',10,'30 second',1,1,20},
{'zacht','Middle',30,'30 second',1,21,40},
{'medium','Middle',50,'30 second',1, 41,60},
{'hard','High',70,'30 second',1,61,80},
{'extra', 'High', 90,'30 second',1,81,100}
}
local function xxx(aa)
for _, record in ipairs(volume_states) do
if isInteger(aa) then
if volume >= record[6] and volume <= record[7] then -- figure out aa in which range it is and then use those values
return record[1],record[2],record[3],record[4],record[5]
else
if record[1] == volume then
return record[1],record[2],record[3],record[4],record[5]
end
end
end
end
a=10 --of
a="10" --of
a="medium"
if isInteger(a) then
aa= tonumber(a)
else
aa=a
end
test1,test2,test3,test4,test5 = XXX(aa)