EDIT - I prefer the second version below: Haven't seen that mod before, but this should do it. Syntax: !togglegrid If a token is selected before running, then the grid on the selected token's page will be toggled. Otherwise, the grid on the current player ribbon page will be toggled. A message is whispered to chat based on this condition. const ToggleGrid = (() => {
const scriptName = 'ToggleGrid';
const version = '0.1.0';
const checkInstall = () => {
log(`-=> ${scriptName} v${version} <=-`);
};
const ToggleGrid_handleInput = (msg) => {
if(msg.type=="api" && msg.content.indexOf("!togglegrid") === 0 ) {
let pageID, gmMessage;
if (msg.selected !== undefined) {
let selectedTok = getObj("graphic",msg.selected[0]._id);
if (selectedTok) {
pageID = selectedTok.get('_pageid');
gmMessage = 'Selected token page grid has been toggled'
}
} else {
pageID = Campaign().get('playerpageid');
gmMessage = 'No token selected: Player ribbon page grid has been toggled'
}
let page = getObj('page', pageID);
if (page) {
let newGridStatus = !page.get('showgrid');
page.set('showgrid',newGridStatus);
gmMessage = gmMessage + ` to ${newGridStatus}`
sendChat(scriptName, `/w gm ${gmMessage}`)
}
}
};
const registerEventHandlers = () => {
on('chat:message', ToggleGrid_handleInput);
};
on('ready', () => {
checkInstall();
registerEventHandlers();
});
})();