Alright, how about doing it this way then.
affs = {}
cures = {}
queue =
{
"health_low",
"mana_low",
"paralysis",
"health_medium",
"mana_medium"
}
cures["health_low"] = "sip health"
cures["mana_low"] = "sip mana"
cures["paralysis"] = "focus body"
for a in ipairs (queue) do
if affs[queue[a]] then
send(cures[[queue[a]])
end
end
it seems to be curing fine and in order, but with such a small queue I'm wondering if it's partially by luck, but someone said ipairs with a simple table with no keys keeps it in order. Is this true? If so, I might just use that solution instead.
One thing I was wondering is if I had multiple cures listed though like:
cures["paralysis"] = {focus body, sip allheale}
I'd want to run through that list and only send one. That is, not focus body and sip allheale at the same time for the same cure. Since I check my cures on each prompt, I'm scared I'll try to focus body on one, then sip allheale on another or even try to do both at the same time.
How would I pick just one from this new mini table? I guess I would just do another for loop inside there?
for a in ipairs cures[queue[a]] do
send(cures[queue[a]]
end
This would make it loops through all the cures in the list. I was thinking instead of sending things to the world, I'd make the keys functions in that table, and these functions would check for balances, so I wouldn't send things off balance...something like this:
function focus_body()
if balance.focus = true then
Send("focus body")
balance.focus = false
end
end
function sip_allheale()
if balance.allheale = true then
Send("sip allheale")
balance.allheale = false
end
end
cures["paralysis"] = { function () sip_allheale() end, function focus_body() end}
and then do the loop
for a in ipairs cures[queue[a]] do
cures[queue[a]]()
end
That means I'll send only the cures that are onbalance, but I'd still send them both if they were offbalance. I'm also thinking that maybe my inexperience with lua makes it hard to see a better way that a for loop within a for loop, so is there a better way?
Final code would end up like this:
affs = {}
cures = {}
queue =
{
"health_low",
"mana_low",
"paralysis",
"health_medium",
"mana_medium"
}
function focus_body()
if balance.focus = true then
Send("focus body")
balance.focus = false
end
end
function sip_allheale()
if balance.allheale = true then
Send("sip allheale")
balance.allheale = false
end
end
cures["paralysis"] = { function () sip_allheale() end, function focus_body() end}
for a in ipairs (queue) do
if affs[queue[a]] then
for a in ipairs cures[queue[a]] do
(cures[queue[a]]()
end
end
end
looks sloppy, and I'm sure I'll be trying to cure the same twice.