Summary
Add a skip parameter to ConnectUtil.tagInstance so it fires the appropriate
callback immediately on call added if the instance is already tagged,
removed if it is not matching the behaviour attributeChanged and
valueChanged already provide.
Motivation
tagInstance reacts to future tag changes but ignores current state. To handle
the initial case you have to write a manual check alongside the call:
IRL example of my use case:
-- manual initial state check
if player.Character:HasTag(Registry.tags.participant) then
onPlayerParticipatingInMatch()
else
onPlayerInLobby()
end
-- then the reactive listener
ConnectUtil.tagInstance(player.Character, Registry.tags.participant,
function(_instance) onPlayerParticipatingInMatch() end,
function(_instance) onPlayerInLobby() end
)
The check and the listener are saying the same thing twice. Every other
ConnectUtil function that reads current state fires immediately by default and
accepts skip = true to opt out. tagInstance should be consistent.
Design
Add skip: boolean? as a fourth parameter. When skip is absent or false,
tagInstance fires one callback immediately after wiring the signals:
- instance has the tag → calls
added(instance)
- instance does not have the tag → calls
removed(instance)
With skip = true neither callback fires on call; behaviour is unchanged from
today.
function Module.tagInstance(
instance: Instance,
tag: string,
added: (Instance) -> ()?,
removed: (Instance) -> ()?,
skip: boolean?
)
The call site above collapses to:
ConnectUtil.tagInstance(player.Character, Registry.tags.participant,
function(_instance) onPlayerParticipatingInMatch() end,
function(_instance) onPlayerInLobby() end
)
Drawbacks
- Callers who previously paired a manual
HasTag check with tagInstance will
fire the callback twice on startup unless they add skip = true. This is a
silent behaviour change for existing call sites.
Alternatives
Keep the manual check
Works, but duplicates the branch logic and breaks the consistency every other
ConnectUtil function already provides.
Summary
Add a
skipparameter toConnectUtil.tagInstanceso it fires the appropriatecallback immediately on call
addedif the instance is already tagged,removedif it is not matching the behaviourattributeChangedandvalueChangedalready provide.Motivation
tagInstancereacts to future tag changes but ignores current state. To handlethe initial case you have to write a manual check alongside the call:
IRL example of my use case:
The check and the listener are saying the same thing twice. Every other
ConnectUtilfunction that reads current state fires immediately by default andaccepts
skip = trueto opt out.tagInstanceshould be consistent.Design
Add
skip: boolean?as a fourth parameter. Whenskipis absent orfalse,tagInstancefires one callback immediately after wiring the signals:added(instance)removed(instance)With
skip = trueneither callback fires on call; behaviour is unchanged fromtoday.
The call site above collapses to:
Drawbacks
HasTagcheck withtagInstancewillfire the callback twice on startup unless they add
skip = true. This is asilent behaviour change for existing call sites.
Alternatives
Keep the manual check
Works, but duplicates the branch logic and breaks the consistency every other
ConnectUtilfunction already provides.