Create a table using variables as keys

Hi guys,

I’m attempting to use the Firebase API and I’m required to construct a table from key and path variables:
function _device_status_update( key, value ) { _firebase.update( _devicePath, { key : value } ); }

However, I can’t find syntax that lets me create a table key from a variable (key:value is an error), any suggestions?

Many thanks

IIRC, you use array syntax for this:

`local table = {};
table.aKey <- 45;
local keyname = "aKey";
server.log(table[keyname]);
// Logs ‘45’`

this also works.

table <- {};
local key = “slot1”;
local value = “value1”

table[key] <- value;

Thanks guys,

I came to this same conclusion, couldn’t find anything in-line but this solution works well.

`function _device_status_update( key, value )
{
local data = {};
data[key] <- value;

    _firebase.update( _devicePath, data );
}`

for brevity, this works equally well…

`function _device_status_update( key, value )
    {        
        _firebase.update( _devicePath, { [key]=value } );
    }`

Super thumbs up