Hi, I'm new to Mudlet and Lua as well and was wondering if it is possible to dynamically generate setPopup() commands?
For example, here is a slightly revised version of the documentation on setPopup() :
selectString("Hello", 1)
setPopup("main", {[[send("bye")]], [[send("hi")]]}, {"left-click or right-click and do first item to send bye", "click to send hi"})
and here is an idea of what I had in mind (hopefully it's legible - I know there's several of syntax errors there, but don't judge me, I'm new
)
testVar = {
["bye"] = "left-click or right-click and do first item to send bye",
["hi"] = "click to send hi"
}
selectString("Hello", 1)
setPopup("main", {
for k, v in pairs(testVar)
[[send(k)]],
end
}, {
for k, v in pairs(testVar)
[[v]],
end
})
Just for kicks I also tried pre-constructing the setPopup() commands into a variable and using that in the setPopup() call, but this failed as well. Echoing out the resulting string looked promising, but putting the variable into the setPopup() call proved fruitless.
testVar = {
["send(\"bye\")"] = "left-click or right-click and do first item to send bye",
["send(\"hi\")"] = "click to send hi"
}
testCons = "{"
for k, v in pairs(testVar) do
testCons = testCons .. "[[".. k .."]], "
end
testCons = testCons .. "}, {"
for k2, v2 in pairs(testVar) do
testCons = testCons .. "[[".. v2 .."]], "
end
testCons = testCons .. "}"
display(testCons)
selectString("Hello", 1)
setPopup("test", testCons)
So there are my bumbling newbie attempts at this, hopefully someone can point me in the right direction in order to do this correctly or at least let me know that it isn't possible so I can stop wasting time with it.
Thanks in advance.