I was messing around, seeing how far along Mudlet has gotten and ended up with this. Seems to work okay and someone might be interested in it, so I thought I'd post it.
It's basically an alias, ^def$ which sends "defences" and displays the result in a slightly more appealing (for me) format, like so:
Any class defs/blessings/etc. you'll have to put in yourself. Just add the defence name to the "def" table, and make a trigger that does defDef("weathering") on the message you see when you normally type DEF.
I'm no Mudlet expert obviously, so there's probably loads of things I did the wrong/hard way, but so far it seems to work for me. I also couldn't quite figure out the export button and had to manually paste together a bunch of things, so it might not work at all.
Defence list for Achaea
Defence list for Achaea
- Attachments
-
- def_display.xml
- (27.01 KiB) Downloaded 906 times
Re: Defence list for Achaea
This is great actually and it works well enough for me. Anyone know of a way to organize them though?
Re: Defence list for Achaea
It's a bit complicated to do. Lua doesn't care about the order of this type here (where it's key = value), so the way it saves them is rather random.
It is possible to make it go in an orderly fashion, someone suggested to try "so instead of "for k,v in pairs(t) do ..." you can do "for i,k in ipairs(keys) do local v = t[k]; if v ~= nil then ..."" but I haven't figured that out yet (didn't seem to be working for me).
It is possible to make it go in an orderly fashion, someone suggested to try "so instead of "for k,v in pairs(t) do ..." you can do "for i,k in ipairs(keys) do local v = t[k]; if v ~= nil then ..."" but I haven't figured that out yet (didn't seem to be working for me).
Re: Defence list for Achaea
As I understand it, the ipairs solution won't work, because it requires a numbered list, which doesn't give you the option of saying whether a def is present/absent. You would need two lists, the one you have already, and a numbered list to hold the order.Vadi wrote:It's a bit complicated to do. Lua doesn't care about the order of this type here (where it's key = value), so the way it saves them is rather random.
It is possible to make it go in an orderly fashion, someone suggested to try "so instead of "for k,v in pairs(t) do ..." you can do "for i,k in ipairs(keys) do local v = t[k]; if v ~= nil then ..."" but I haven't figured that out yet (didn't seem to be working for me).
Re: Defence list for Achaea
That's what that code does, caled. Table keys is a standard ipairs-compatible indexed array.Caled wrote:As I understand it, the ipairs solution won't work, because it requires a numbered list, which doesn't give you the option of saying whether a def is present/absent. You would need two lists, the one you have already, and a numbered list to hold the order.Vadi wrote:It's a bit complicated to do. Lua doesn't care about the order of this type here (where it's key = value), so the way it saves them is rather random.
It is possible to make it go in an orderly fashion, someone suggested to try "so instead of "for k,v in pairs(t) do ..." you can do "for i,k in ipairs(keys) do local v = t[k]; if v ~= nil then ..."" but I haven't figured that out yet (didn't seem to be working for me).
For example,
Code: Select all
--Of course with 2 keys, they might get ordered properly anyway
t = {}
t["bar"] = "randomThing1"
t["foo"] = "randomThing2"
--foo always before bar (lame, I know)
keys = {"foo", "bar"}
--Now print, as an example
for index,key in ipairs(keys) do
local val = t[key];
if val ~= nil then
echo(key .. "=" .. t[key] .. "\n")
end
end
You could mash those together into one table if you wanted, although it'd be even slower (more work) and would be rather messy to access -- you'd almost need a getKey()/getValue option as I don't know if lua supports operator overloading...
I'm not sure, you might be able to use a linked list of some sort. Although randomly accessing elements wouldn't be so simple...
Re: Defence list for Achaea
Vadi wrote:It's a bit complicated to do. Lua doesn't care about the order of this type here (where it's key = value), so the way it saves them is rather random.
It is possible to make it go in an orderly fashion, someone suggested to try "so instead of "for k,v in pairs(t) do ..." you can do "for i,k in ipairs(keys) do local v = t[k]; if v ~= nil then ..."" but I haven't figured that out yet (didn't seem to be working for me).
Code: Select all
if not php then php = {} end
function php:Table(...)
local newTable,keys,values={},{},{}
newTable.pairs=function(self) -- pairs iterator
local count=0
return function()
count=count+1
return keys[count],values[keys[count]]
end
end
newTable.count=function(self) -- count return
return table.getn(keys)
end
setmetatable(newTable,{
__newindex=function(self,key,value)
if not self[key] then table.insert(keys,key)
elseif value==nil then -- Handle item delete
local count=1
while keys[count]~=key do count = count + 1 end
table.remove(keys,count)
end
values[key]=value -- replace/create
end,
__index=function(self,key) return values[key] end
})
return newTable
end
Code: Select all
local testArry = php:Table()
testArry["test1"] = "another test"
testArry["test2"] = "one more"
for k,v in testArry:pairs() do print(k,v) end
Re: Defence list for Achaea
That's a neat tip. Thanks!