I’m retrieving field names from a database and trying to access a lua table index containing the field name. My code is:
for row in globalData.db:nrows([[SELECT bonusValue, name FROM buildingsBonuses WHERE buildingId = "]]..v[1]..[[" AND id = resourceId]]) do print(inspect(row.name)) local test = row.name print(inspect(globalData.userResources[test][bonus])) -- globalData.userResources[row.name]bonus = globalData.userResources[row.name]bonus + row.bonusValue end
Would return:
"cash" 0 nil "happiness" 0 nil
And crash if I un-comment the last line.
How can I address this? Any alternative way to access a table when retrieve the indexes from a database (and getting as a string). I basically want to access globalData.userResources.cash.bonus and globalData.userResources.happiness.bonus
I also tried local test = row.name…‘bonus’ but same result