Quote:
Would something using ArrayListKeys and ArrayGet be better? Also how to implement?
I wouldn't use the Array stuff in MUSHclient, as that was added before Lua scripting. The Lua tables make managing table data (arrays) much more natural.
Quote:
Would:
badpeople = {}
badpeople.wholist = {
name = "%1"
location = "%2"
capture what I want?
This example would create a new table (assuming this is in a trigger) for each person, and thus the table would only every have one entry.
Something like this might work better for you:
badpeople = badpeople or {} -- make table if necessary
badpeople ["%1"] = "%2" -- save location of this person
The first line creates the table "badpeople" if it does not exist.
The second line adds (or replaces) an entry, keyed by the person's name, with their location as the table data.
Quote:
Then do like...
function wholisting (name, line, wildcards)
if city == badpeoplecity then
table.foreach (badpeople.wholist) ColourNote("red", "black", "[BADPEOPLE]:”, print (badpeople.wholist.name) .. “ - “ .. print (badpeople.wholist.location) .. )
end -- function
The syntax is a bit skewed here. For one thing table.foreach is deprecated, and may not be in a future version. For another the table.foreach expects its second argument to be a function, to which it passes each item in the table it is iterating over. This code below should work, and looks simpler anyway:
function wholisting (name, line, wildcards)
for name, location in pairs (badpeople) do
ColourNote ("red", "black",
"[BADPEOPLE]: '" .. name .. "' - '" .. location .. "'")
end -- for
end -- function
Inside the for loop above, I am retrieving the key and value of each table item (calling them 'name' and 'location') and using them inside a ColourNote. |