A condition on the player's own state, from Scope.when, for a
command's enabled or checked. The player evaluates it, again on
every change of that state, whether or not the plugin runs.
Remarks
Combine conditions with and, or and not; each returns a new
condition and leaves the original as it was. A condition is data: it
reads nothing in the plugin and keeps no listener, so a plugin whose
menu state is made of conditions may be stopped while idle (lazy
activation) and its menu stays current. A function (see Bindable)
keeps working; one that reads plugin.player.state or another service's
state keeps the plugin running so the SDK can evaluate it.
Example: Enable an item while a frame can be saved
"Save Snapshot" is greyed out with its reason unless a media file is
open at a frame the player can capture. The condition is sent with the
command and evaluated by the player, so the item follows playback even
while the plugin is stopped; with an enabled condition the player
shows the reason only while the item is disabled.
const { when } = plugin; plugin.commands.add({ id:"save", path: ["@video", "Save Snapshot"], enabled:when.can("snapshot").and(when.phase("ready", "ended"), when.stream.not()), reason:"No frame to capture", // shown only while disabled run:saveSnapshot, });
A condition on the player's own state, from Scope.when, for a command's
enabledorchecked. The player evaluates it, again on every change of that state, whether or not the plugin runs.Remarks
Combine conditions with
and,orandnot; each returns a new condition and leaves the original as it was. A condition is data: it reads nothing in the plugin and keeps no listener, so a plugin whose menu state is made of conditions may be stopped while idle (lazy activation) and its menu stays current. A function (see Bindable) keeps working; one that readsplugin.player.stateor another service's state keeps the plugin running so the SDK can evaluate it.Example: Enable an item while a frame can be saved
"Save Snapshot" is greyed out with its reason unless a media file is open at a frame the player can capture. The condition is sent with the command and evaluated by the player, so the item follows playback even while the plugin is stopped; with an
enabledcondition the player shows thereasononly while the item is disabled.Since
1.5.40