Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Help with making a list from table comparisons and output notice
Help with making a list from table comparisons and output notice
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Hoplo
(16 posts) Bio
|
Date
| Thu 30 Aug 2012 01:38 AM (UTC) |
Message
| I have a "friends" function that checks the names obtained from who to a table with various character names and the clan they belong to. I works, but the final output format is not what I want, and I have not been able to figure out how to make it work.
the friend table looks like this:
friendstbl = {
Guardians = {"Balso", "Morti", "Salian"},
Regent = {"Hogt", "Filso", "Bese", "Moux"},
Fiendish = {"Tars", "Ruerk"},
}
and the function I currently use:
function dofriends()
local fCount = 0
if (whonames ~= nil and #whonames >= 1) then
for i, c in pairs(friendtbl) do
for n, m in pairs(c) do
for a, b in ipairs(whonames) do
if b == m then
fCount = fCount + 1
Note ("<"..i.."> "..b)
end
end
end
end
end
end
This gives me an output of(those currently online):
<Guardians> Balso
<Guardians> Salian
<Regent> Filso
<Guardians> Morti
What I would like to have is something like:
3 <Guardians> Balso, Salian, Morti
1 <Regent> Filso
Any suggestions or help would be greatly appriciated. Thanks
| Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Fri 31 Aug 2012 11:07 PM (UTC) |
Message
|
-- test data
whonames = { "Balso", "Salian", "Filso", "Morti" }
friendstbl = {
Guardians = {"Balso", "Morti", "Salian"},
Regent = {"Hogt", "Filso", "Bese", "Moux"},
Fiendish = {"Tars", "Ruerk"},
}
if whonames == nil or #whonames < 1 then
return
end -- if no-one online
-- convert people online into keyed table
local t = {}
for _, v in ipairs (whonames) do
t [v] = true
end -- for
-- do each group of friends
for friendType, friendList in pairs (friendstbl) do
local count = 0
-- now check each friend to see if online
for _, name in ipairs (friendList) do
if t [name] then
if count == 0 then
Tell ("<" .. friendType .. "> ")
else
Tell (", ")
end -- if
count = count + 1
Tell (name)
end -- if that friend online
end -- for
if count > 0 then
Note ("") -- newline
end -- if
end -- for each type of friend
Output:
<Guardians> Balso, Morti, Salian
<Regent> Filso
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
8,726 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top