This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Use of a table as a global variable for several scripts
#1
Hi everyone!

I try to create a global variable, a table, so that several scripts insert new records. But everytime a script adds a new record, next time, I find the table empty. 

In a library declare the tables (withouth the local modificator)
---------------------------------------------------------------
tablaknx = {}


devices = {
    { DIRETS = '1xx', VALOR = '17east' },
    { DIRETS = '2xx', VALOR = '27west' },
    { DIRETS = '3xx', VALOR = '37mid' }
}
--------------------------------------------------------------- 

The other scripsts would be like this:

function add_tablaknx(direts, nombre, valor)
  log(tablaknx)
  table.insert(tablaknx, {DIRETS = direts, NOMBRE = nombre, VALOR = valor})
  table.insert(tablaknx, {DIRETS = direts, NOMBRE = nombre, VALOR = valor})
  log(tablaknx)
 
 
return 1
end


function add_devices(direts, valor)
  log(devices)
  table.insert(devices, 1, 11111111111)

  log(devices)
 
 
return 1
end



add_tablaknx('10/www0/0', 'fghqwrewehsg', 'twwwrue')
add_devices('10/www0/0',  'twwwrue')


It works, the register is added, but the next time it tries to add a new register the table it's empty.

Obviously I'm doing it the wrong way. It's possible to implement this with permanent changes? I don't want to use storage becouse the info in this table is going to change quickly and I don't want to destroy the SD Card

Thanks!!!

Kike
Reply


Messages In This Thread
Use of a table as a global variable for several scripts - by kike - 28.01.2026, 09:25

Forum Jump: