Using a vairable to represent a device_type

I have been trying to use a variable in place of the full device type without success. Please let me know what I am missing. There aren’t any error messages. Just doesn’t change the value in the Multistring device.

local dID = 210
local test = [[“urn:upnp-org:serviceId:VContainer1”, “Variable2”]]
local saved_number = 5
luup.variable_set(test,saved_number, dID)

I have tried:
local test = ‘“urn:upnp-org:serviceId:VContainer1”, “Variable2”’
as well.

Thank you, Mark

https://www.lua.org/pil/11.1.html
Still learning syntax my self but from above site .
local test = {“val1”, “val2”}
test[0]

Thank you for the reply. I’m not looking to use a table. I just want to replace:
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable2”,saved_number, dID)
with the variable “test” to replace “urn:upnp-org:serviceId:VContainer1”, “Variable2”
Thank you, Mark

Isn’t “urn:upnp-org:serviceId:VContainer1”, “Variable2” 2 seperate parameters in variable set?

you are feeding the function 3 parameters not 4

I can see what you are trying to do but as @ElCid is trying to explain, lua doesn’t work that way.
You need to understand the type of objects you are using.
The expression you are using, “Luup.variable_set” is a function with a number of expected arguments/parameters. It is expecting 4. You are trying to replace the first two with a single variable containing two strings containing the name of the two variables to be used as parameters.
For this to work, you will need evaluate the two string names back into variables. This is not very efficient and will end up making you write more code than the code you are trying to save by creating this shortcut…

Thanks for the reply.
I just tried:
local dID = 210
local test = [[“urn:upnp-org:serviceId:VContainer1”]]
local test2 = [[“Variable2”]]
local saved_number = 5
luup.variable_set(test,test2,saved_number, dID)
without sucess.

local dID = 210
local test = "urn:upnp-org:serviceId:VContainer1"
local test2 = variablename
local saved_number = 5
luup.variable_set(test,test2,saved_number, dID)

should work assuming test2 is the name of the variable

That gets it working. Thank you ElCid and rafale77! :grinning:

More importantly, I learned something. I’m a slow study, but persistent.

Thank you, Mark

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.