I've pretty much got it working correctly, the only part that doesn't work currently is the call when the turn order is closed....Here's what i got so far. // VARIABLE & FUNCTION DECLARATION var TurnOrderSight = TurnOrderSight || {}; var AllSightOn = AllSightOn || {}; var AllSightOff = AllSightOff || {}; on("change:campaign:turnorder", function(obj) { TurnOrderSight(); }); on("change:campaign:initiativepage", function(obj) { if(obj == false) { AllSightOn(); }; });
function TurnOrderSight () { if (!Campaign().get("turnorder")) { AllSightOn (); return; }; var turn_order = JSON.parse(Campaign().get("turnorder")); if (!turn_order.length) { AllSightOn (); return; }; // Exit script if custom item on turn order tracker instead of a token... if (turn_order[0].id == -1) return; AllSightOff (); var current_token = getObj("graphic", turn_order[0].id); current_token.set({ "light_hassight": true, }); };
function AllSightOn () { var currentPageGraphics = findObjs({ _pageid: Campaign().get("playerpageid"), _type: "graphic", _subtype: "token", }); _.each(currentPageGraphics, function(obj) { //Do something with obj, which is in the current page and is a graphic. obj.set({ "light_hassight": true, }); }); };
function AllSightOff () { var currentPageGraphics = findObjs({ _pageid: Campaign().get("playerpageid"), _type: "graphic", _subtype: "token", }); _.each(currentPageGraphics, function(obj) { //Do something with obj, which is in the current page and is a graphic. obj.set({ "light_hassight": false, }); }); };