Methods

Learn more about methods of a pui element

:depend(...)

Sometimes you want to hide certain elements to not mess up the menu. It may look simple but actually it's rather difficult and complicated. But pui can make this as easy as pie.

:depend(...) is a method of a pui element, which creates a dependence on elements passed as arguments.

Its arguments can be either elements themselves (generally switches), or tables, which contain ref, condition, invert.

In most of the cases, it looks like this: :depend( {ref, condition}, {ref2, condition2}, ... )

Also, if you want to "disable" elements (lock them), you can do it with :depend(true, ...)

It's worth to note that pui::group supports :depend() as well.

Study these examples:

This is a common example of the use of :depend(...). As you can see, there are two labels showing statuses of a switch.

local switch = group:switch("Master switch")
local status1 = group:label("...is enabled!")
local status2 = group:label("...is disabled!")

status1:depend( {switch, true} )  -- or simply :depend(switch)
status2:depend( {switch, false} )

There are a lot of ways to use :depend() that I can't even imagine.

:set_event(event, func, condition*)

This methods is used to call functions in events when a certain condition is met. You can unset this behavior via :unset_event(event, func). You can't unset anonymous functions.

local enabled = pui.switch("Main", "Enable", "Name")

local antiaim = function (cmd)
    print(cmd.choked_commands)
end

enabled:set_event("createmove", antiaim)

Last updated