Having an issue with tables in Mudlet
function checkMobsInRoom()
local targName = ""
for k, v in pairs(bashingTable) do
if table.contains(mobsInRoom, v) and target:title() ~= k:title() and autoBashing() then
target(k)
return
elseif type(bashingTable[k]) == "table" then
targName = k
for _, v in pairs(bashingTable[k]) do
if table.contains(mobsInRoom, v) and target:title() ~= targName:title() and autoBashing() then
target(targName)
return
end
end
end
end
end
function bash()
if bal() and autoBashing == "true" then
send("qjab "..target)
end
endSo I have that. Don't be fooled by "autoBashing", it's just what I call it. I'm a trying to pull from the following table (it is very small, just testing things right now before I start populating the table more with different areas and such) so that if the mob is in the room, it will switch targets to the appropriate alias.bashingTable = {
horde = "an orcish grunt", "an orcish mage",
}Thanks in advance for any and all assistance! This is my very first time working with functions and tables, so I feel super lost and overwhelmed. 0
Comments
bashingTable = { horde = {"an orcish grunt", "an orcish mage", "etc"}}The horde entry should also be a table, as how you had it written would just set horde to the first string ("an orcish grunt") and ignore anything supplied after it.
As for the loops, I rearranged them a bit based on what you have there.
-- it doesn't matter what's in the table, this will loop through it -- we can sort out table/not table later for k, v in pairs(bashingTable) do if type(v) == "table" then -- is the entry a table? then we want to check if any of the mobs match -- if so, use a generic target for _, mob in pairs(v) do if table.contains(mobsInRoom, mob) and target:title() ~= targName:title() and autoBashing() then target(k) return end end else -- it's not a table - is this area one of those annoying ones with few generic targets? -- check to see if any of the mobs match and target by name(assuming id from gmcp) instead if table.contains(mobsInRoom, v) and target:title() ~= targName:title() and autoBashing() then target(targName) return end end end
You are not setting targName in what you posted, so that might be part of the issue.I believe you could also just not the type==table check and use a single loop, though it may require some modification on how you set up the bashingTable.