Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, 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.
Entire forum
➜ MUSHclient
➜ Lua
➜ List of Enabled Triggers Group
List of Enabled Triggers Group
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Solara
USA (59 posts) Bio
|
Date
| Wed 19 Jul 2023 07:33 PM (UTC) Amended on Wed 19 Jul 2023 10:01 PM (UTC) by Solara
|
Message
| I'm trying to get a list of enabled trigger GROUPs.
I have the following, but it shows ALL enabled individual triggers, and the Group name. So the list will show multiple instances of the same Group name. Is there an easy way to parse/sort the table to remove duplicates?
triggerlist = GetTriggerList()
activetrigger = {}
if triggerlist then
for k, v in ipairs (triggerlist ) do
if GetTriggerInfo (tostring (v), 8) == true then
table.insert (activetrigger, tostring (GetTriggerInfo (v,26)))
else
end
end
end
for k, v in ipairs (activetrigger ) do
table.sort (activetrigger)
print (k,v)
end
| Top |
|
Posted by
| Fiendish
USA (2,533 posts) Bio
Global Moderator |
Date
| Reply #1 on Wed 19 Jul 2023 09:07 PM (UTC) Amended on Wed 19 Jul 2023 09:10 PM (UTC) by Fiendish
|
Message
| You can get just the list of unique groups if instead of doing
table.insert (activetrigger, tostring (GetTriggerInfo (v,26)))
you do
activetrigger[GetTriggerInfo(v,26) or ""] = true
and then instead of
for k, v in ipairs(activetrigger) do
print (k, v)
end
you do
for group, _ in pairs(activetrigger) do
print(group)
end
This treats the group name as the key in the table instead of as the value assigned to some meaningless integer key that you then need to deduplicate. Storing the group name as the key will guarantee that each group only gets stored once. But then you need to use pairs and not ipairs to loop over the list. |
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Solara
USA (59 posts) Bio
|
Date
| Reply #2 on Wed 19 Jul 2023 09:39 PM (UTC) Amended on Wed 19 Jul 2023 10:01 PM (UTC) by Solara
|
Message
| Wow, I'll have to study that and figure out what was done. But it works great. Thanks!
Here's my final alias to get the list of enabled triggers by Group name, in alphabetical order:
require "pairsbykeys"
triggerlist = GetTriggerList()
activetrigger = {}
if triggerlist then
for k, v in ipairs (triggerlist ) do
if GetTriggerInfo (tostring (v), 8) == true then
activetrigger[GetTriggerInfo(v,26) or ""] = true
else
end
end
end
for group, _ in pairsByKeys (activetrigger ) do
print (group)
end
| Top |
|
Posted by
| Fiendish
USA (2,533 posts) Bio
Global Moderator |
Date
| Reply #3 on Wed 19 Jul 2023 10:44 PM (UTC) Amended on Thu 20 Jul 2023 03:24 PM (UTC) by Fiendish
|
Message
| You don't need the empty else clause. You can just do if/end without else.
Here is where I tell you based on decades of experience that you really should pay attention to keeping strict indentation and line spacing patterns.
Without any content modifications, your code should be formatted more like
require "pairsbykeys"
triggerlist = GetTriggerList()
activetrigger = {}
if triggerlist then
for k, v in ipairs(triggerlist) do
if GetTriggerInfo(tostring(v), 8) == true then
activetrigger[GetTriggerInfo(v, 26) or ""] = true
else
end
end
end
for group, _ in pairsByKeys(activetrigger) do
print(group)
end
The Lua engine lets you get away with whitespace chaos, but human eyes and brains do not. Making your indentation match the contents makes reading and understanding the code later require a lot less mental energy. |
https://github.com/fiendish/aardwolfclientpackage | 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.
3,470 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top