I've been working on this for a little while here, and I came up with something that seems to work. It's so "ugly" I can't believe it works. Surely there is a more elegant way to do this:
Here's my input:
You are carrying a mace, some platemail, a gold-ring, a jade-ring, a
glass-ring, a brass-ring, a flask, a key, a flask, a flask, a flask, a flask, a
flask, a flask, your spellbook and 55932 gold pieces.
My "countflasks" alias returns: 7
Which is exactly what I want.
But here is the God-awful mess that calculates the flasks.
require "wait"
flasks = 0
invlist1 = nil
invlist2 = nil
invlist3 = nil
invlist4 = nil
wait.make (function ()
Send ("inventory")
invlist1 = wait.regexp ("^You are carrying *",1)
if (invlist1) then
invlist2 = wait.regexp ("^(.*?)$", 1)
-- I know this next line is WRONG
-- this will never match what I want
if not (invlist2 == "* gold pieces\.$") then
invlist3 = wait.regexp ("^(.*?)$", 1)
-- I know this next line is WRONG
-- this will never match what I want
if not (invlist3 == "* gold pieces\.$") then
-- 4 lines of inventory should do it.
-- We are limited to the number of items
-- we can carry.
invlist4 = wait.regexp ("^(.*?)$", 1)
end
end
else
-- This should never happen.
Note ("Failed to acquire inventory list")
end
if (invlist1) then
for k, v in ipairs (utils.split (invlist1, ",")) do
if (Trim (v) == "flask") or (Trim (v) == "a flask") then
flasks = flasks +1
end
end
if (invlist2) then
for k, v in ipairs (utils.split (invlist2, ",")) do
if (Trim (v) == "flask") or (Trim (v) == "a flask") then
flasks = flasks +1
end
end
if (invlist3) then
for k, v in ipairs (utils.split (invlist3, ",")) do
if (Trim (v) == "flask") or (Trim (v) == "a flask") then
flasks = flasks +1
end
end
if (invlist4) then
for k, v in ipairs (utils.split (invlist4, ",")) do
if (Trim (v) == "flask") or (Trim (v) == "a flask") then
flasks = flasks +1
end
end
end
end
end
end
Note (flasks)
end)
|