permGroup Rewrite

Share your scripts and packages with other Mudlet users.
Post Reply
Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

permGroup Rewrite

Post by Jor'Mox »

I wrote an updated version of the permGroup function that allows you to specify a parent group for the group you are creating. It still works in the same manner that permGroup does, meaning that what is created is not actually a group, but rather a blank trigger/alias/timer. The original syntax still works as expected (permGroup(name, type)). To specify a parent, just add the name as the last argument (permGroup(name, type, parent)).
Code: [show] | [select all] lua
--Overwriting the existing permGroup function so that it supports
--nesting groups. Even though the function technically does not
--create "groups".
function permGroup(name, itemtype, parent)
    assert(type(name) == "string", "permGroup: need a name for the new group")
    parent = parent or ""

    local t = {
        timer = function(name, parent)
            return not (permTimer(name, parent, 0, "") == -1)
        end,
        trigger = function(name, parent)
            return not (permSubstringTrigger(name, parent, {""}, "") == -1)
        end,
        alias = function(name, parent)
            return not (permAlias(name, parent, "", "") == -1)
        end
    }
    return t[itemtype](name,parent)
 end
Last edited by Jor'Mox on Thu Apr 06, 2017 12:52 pm, edited 2 times in total.

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: permGroup Rewrite

Post by Vadi »

That's awesome. Um... how about pressing the edit button on https://github.com/Mudlet/Mudlet/blob/d ... r.lua#L144 again? :)

Jor'Mox
Posts: 1142
Joined: Wed Apr 03, 2013 2:19 am

Re: permGroup Rewrite

Post by Jor'Mox »

Done. And I went back through the code to eliminate silliness that was going on (some on my part, though it still worked, and some on the part of the original permGroup function, resulting in it always returning true, even if the group wasn't created).

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: permGroup Rewrite

Post by Vadi »

Awesome, thanks. Will have a look.

Post Reply