-- trigger_ref_count - Trigger Reference Counting -- (system_utils_a component) -- Template attachment: any -- Created by: Patrick Ferland -- Created on: 06/23/2008 -- Revision History -- 06/23/2008 P.Ferland - New script --[[ How to use the Trigger Reference Count script 1. Attach trigger_ref_count[11661:2] to the desired template 2. Before sending a reference-counted trigger, send trigger_ref_count_load SendTo(self, 'trigger_ref_count_load', 0, 'trigger_to_count') 3. At the end of any trigger being reference counted, send trigger_ref_count SendTo(self, 'trigger_ref_count', 0, 'trigger_to_count') 4. To test the reference-count state, a. Include this script to gain access to the trigger_ref_count_get function IncludeScript('11661:2') -- trigger_ref_count b. Call trigger_ref_count_get, which should be equal to 0 once all triggers indicate completion if (trigger_ref_count_get('trigger_to_count') == 0) then do_trigger_finished_action() end ]]-- -- Constants -- no constants -- Script Properties Define Properties() trigger_ref_count = {} ExportFunction('trigger_ref_count_get') end -- Commands -- no commands -- Triggers Trigger trigger_ref_count_load(trigger) local count = 0 local script_id = '' for _, script_id in ipairs(GetScriptList(self)) do local script_trigger = '' local script = stylesheet.scripts[script_id] local found = 0 if (script.triggers['trg_' .. trigger] ~= nil) then found = 1 end count = count + found end self.trigger_ref_count[trigger] = count end Trigger trigger_ref_count(trigger) if (self.trigger_ref_count[trigger] ~= nil) then self.trigger_ref_count[trigger] = self.trigger_ref_count[trigger] - 1 end end function trigger_ref_count_get(self, trigger) local count = 0 if (self.trigger_ref_count[trigger] ~= nil) then count = self.trigger_ref_count[trigger] end return count end