zxmatzx
Advanced OT User
Hello,
Im trying to convert a string to a variant that represents a table key
Pseudo-Code, im traveling and don't have access to real code, but its is similar.
I want to access "CONFIG_GERAL.equipsConfigs.armor_slots.slot_1", where the slot number changes and equipament type.
I don't know if i explained in best way... Im using TFS 1.2.
Sorry my english, its not my main language.
Thank you.
Im trying to convert a string to a variant that represents a table key
Pseudo-Code, im traveling and don't have access to real code, but its is similar.
I want to access "CONFIG_GERAL.equipsConfigs.armor_slots.slot_1", where the slot number changes and equipament type.
Lua:
--in lib file
CONFIG_GERAL = {
canWalk = true,
intervalAction = 1000,
healPercent = 20,
equipsConfigs = {
armor_slots = {name = "armor", maxCount = 5, slot_1 = 5, slot_2 = 10, slot_3 = 5, slot_4 = 10, slot_5 = 5},
helmet_slots = {name = "helmet", maxCount = 3, slot_1 = 5, slot_2 = 10, slot_3 = 5},
boots_slots = {name = "boots", maxCount = 1, slot_1 = 5}
},
enabled = true
}
function getSlots(equipType)
local baseTable = "CONFIG_GERAL.equipsConfigs."
local tableIndex = -1
for i = 0, #CONFIG_GERAL.equipsConfigs do
if CONFIG_GERAL.equipsConfigs[i].name == equipType then
tableIndex = i
--break;
end
end
if tableIndex == -1 then
return 0
end
local equipMaxCount = CONFIG_GERAL.equipsConfigs[tableIndex].maxCount
local totalValue = 0
for i = 1, equipMaxCount do
local tmpVar = Variant(baseTable .. "" .. equipType .. "_slots" .. ".slot_" .. i)
totalValue = totalValue + tmpVar
end
return totalValue
end
Lua:
--In action file, called by onUse function
print(getSlots("armor"))
--expected output 35 (slot_1 = 5 + slot_2 = 10 + slot_3 = 5 + slot_4 = 10 + slot_5 = 5)
print(getSlots("helmet"))
--expected output 20 (slot_1 = 5 + slot_2 = 10 + slot_3 = 5)
print(getSlots("boots"))
--expected output 5 (slot_1 = 5)
I don't know if i explained in best way... Im using TFS 1.2.
Sorry my english, its not my main language.
Thank you.