Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Adding new script stops previous one(s) working...

1707938809

Edited 1707939228
Coryphon
Pro
Sheet Author
Hiya, This is an odd situation, I have two scripts which I'm writing for my Lord of the Rings 5e campaign... One is called Daylight, one is called LoTR5e... I added Daylight and it all worked as expected, I add LoTR5e and Daylight stops working... I've cut these scripts down to their basics and I'm flummoxed as to what is going on... I've made a copy of my original game and re-added the scripts and that still doesn't work. In the original game I was also getting duplicate execution of LoTR5e so seemed to be running duplicate sandboxes at various points, I know this can be a thing when sandboxes do not die cleanly... The LoTR5e one, in its full form, had a lot of setInterval, await, async and Promise-related code, but I've taken that out while testing on a copy... I cannot figure out why adding the LoTR5e one disables the Daylight one, and seemingly vice versa! (Should note that before my scripts I have: libInline, TokenMarker and TokenMod in that order, then Daylight, then LoTR5e) EDIT: Have just created a brand new game and ONLY added Daylight and LoTR5e. Daylight does not work and LoTR5e fires twice for every command... Commands !daylight xxx (no output), !lotr5e xxx fires twice with Invalid Command Any help gratefully received!!! ;-) Regards, ~ Coryphon ~ Bit verbose, but here are the scripts: Daylight.js var Daylight = Daylight || (function () {     'use strict';     var version = '0.1';          /*      * General logging function with timestamp      *      * Usage: clog("Starting");      * or for indented text for debug under main function start:      * clog("- Something something");      *      */     function clog(text, chat) {         if(!text.startsWith("- ")) {             text = "Daylight: " + text;         }         var time = new Date();         var timeStr =             ("0" + time.getHours()).slice(-2)   + ":" +             ("0" + time.getMinutes()).slice(-2) + ":" +             ("0" + time.getSeconds()).slice(-2);         log(timeStr + ": " + text);         if(chat) {             sendChat("LoTR5e", "/w " + whoAMI + " " + text);         }     }         /*      *      */     function setDaylight(page, dynamic_lighting_enabled, daylight_mode_enabled, explorer_mode, daylightModeOpacity,                           force_lighting_refresh) {              page.set('dynamic_lighting_enabled', dynamic_lighting_enabled);         page.set('daylight_mode_enabled', daylight_mode_enabled);         page.set('explorer_mode', explorer_mode);         page.set('lightupdatedrop',false);         page.set('daylightModeOpacity', daylightModeOpacity);         page.set('force_lighting_refresh', force_lighting_refresh);     }     /*      *      */     chatMessage = function(msg) {          clog("Messagexx received: " + JSON.stringify(msg));         if(msg.type === 'api'){             if (msg.content.split(' ')[0].toLowerCase() === '!daylight') {                                  clog("Message received: " + JSON.stringify(msg));                 let page = getObj('page', Campaign().get('playerpageid'));                                  if (msg.content.split(' ')[1].toLowerCase() === 'dusk') {                     setDaylight(page, true, true, 'basic', 0.4, true);                     //sendChat('daylight','The sun peaks over the horizon');                 } else if (msg.content.split(' ')[1].toLowerCase() === 'day') {                     setDaylight(page, true, true, 'basic', 1.0, true);                     //sendChat('daylight','The Sun is blazing in the sky');                 } else if (msg.content.split(' ')[1].toLowerCase() === 'night') {                     setDaylight(page, true, true, 'basic', 0.0, true);                     //sendChat('daylight','The dark of night falls');                 } else if (msg.content.split(' ')[1].toLowerCase() === 'moonlight') {                     setDaylight(page, true, true, 'basic', 0.2, true);                     ///sendChat('daylight','The moon shines bright');                 } else if (msg.content.split(' ')[1].toLowerCase() === 'off') {                             setDaylight(page, false, false, 'off', 0.0, true);                     //sendChat('daylight','Turning off UDL');                 }             }         }     }            /*      * Event handling callbacks      */     registerEventHandlers = function() {         on('chat:message', chatMessage);         clog("Ready")     };          /*      * Object 'methods' to return      */     return {         RegisterEventHandlers: registerEventHandlers     }; }());    on('ready',function() {     'use strict';     Daylight.RegisterEventHandlers(); }); And here is LoTR5e (I've cut out all the actual mechanics) var LoTR5e = LoTR5e || (function () { 'use strict'; var version = '0.1';     var whoAMI;     /*      *      */     function clog(text, chat) {         if(!text.startsWith("- ")) {             text = "LoTR5e: " + text;         }         var time = new Date();         var timeStr =             ("0" + time.getHours()).slice(-2)   + ":" +             ("0" + time.getMinutes()).slice(-2) + ":" +             ("0" + time.getSeconds()).slice(-2);         log(timeStr + ": " + text);         if(chat) {             sendChat("LoTR5e", "/w " + whoAMI + " " + text);         }     }     /*      *      */     chatMessage = function(msg) {         if(msg.type === 'api') {             const args = msg.content.split(' ');             if (args[0].toLowerCase() === '!lotr5e') {                 log("chatMessage: " + args);                 whoAMI = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname');                 if (args[1].toLowerCase() === 'info') {                     sendChat("LoTR5e", "/w " + whoAMI + " pathlength, fp_change, fp_setmax, fp_reset");                 }                 else {                     clog("Invalid command!", true);                 }             }         }     }     /*      * Event handling callbacks      */     registerEventHandlers = function() {         on('chat:message', chatMessage);         clog("Ready")     };          /*      * Object 'methods' to return      */     return {     RegisterEventHandlers: registerEventHandlers     }; }()); /*  * Runtime  */ on('ready', function() { 'use strict'; LoTR5e.RegisterEventHandlers(); });
1707941433
The Aaron
Roll20 Production Team
API Scripter
That's really weird.  I don't see anything which would cause them not to work.  I linted both and corrected a few minor typos and inefficiencies, but I don't think that will change the behavior. const Daylight = (() => { const version = '0.1'; //eslint-disable-line no-unused-vars let whoAMI; /* * General logging function with timestamp * * Usage: clog("Starting"); * or for indented text for debug under main function start: * clog("- Something something"); * */ const clog = (text, chat) => { if(!text.startsWith("- ")) { text = "Daylight: " + text; } let time = new Date(); let timeStr = ("0" + time.getHours()).slice(-2) + ":" + ("0" + time.getMinutes()).slice(-2) + ":" + ("0" + time.getSeconds()).slice(-2); log(timeStr + ": " + text); if(chat) { sendChat("Daylight", `/w "${whoAMI}" ${text}`); } }; /* * */ const setDaylight = ( page, dynamic_lighting_enabled, daylight_mode_enabled, explorer_mode, daylightModeOpacity, force_lighting_refresh ) => { page.set({ dynamic_lighting_enabled : dynamic_lighting_enabled, daylight_mode_enabled : daylight_mode_enabled, explorer_mode : explorer_mode, lightupdatedrop : false, daylightModeOpacity : daylightModeOpacity, force_lighting_refresh : force_lighting_refresh }); }; /* * */ const chatMessage = (msg) => { clog("Messagexx received: " + JSON.stringify(msg)); if(msg.type === 'api'){ let args = msg.content.split(/\s+/); if (args[0].toLowerCase() === '!daylight') { whoAMI = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); clog("Message received: " + JSON.stringify(msg)); let page = getObj('page', Campaign().get('playerpageid')); if (args[1].toLowerCase() === 'dusk') { setDaylight(page, true, true, 'basic', 0.4, true); //sendChat('daylight','The sun peaks over the horizon'); } else if (args[1].toLowerCase() === 'day') { setDaylight(page, true, true, 'basic', 1.0, true); //sendChat('daylight','The Sun is blazing in the sky'); } else if (args[1].toLowerCase() === 'night') { setDaylight(page, true, true, 'basic', 0.0, true); //sendChat('daylight','The dark of night falls'); } else if (args[1].toLowerCase() === 'moonlight') { setDaylight(page, true, true, 'basic', 0.2, true); ///sendChat('daylight','The moon shines bright'); } else if (args[1].toLowerCase() === 'off') { setDaylight(page, false, false, 'off', 0.0, true); //sendChat('daylight','Turning off UDL'); } } } }; /* * Event handling callbacks */ const registerEventHandlers = () => { on('chat:message', chatMessage); clog("Ready"); }; /* * Object 'methods' to return */ return { RegisterEventHandlers: registerEventHandlers }; })(); on('ready', Daylight.RegisterEventHandlers ); const LoTR5e = (() => { const version = '0.1'; //eslint-disable-line no-unused-vars let whoAMI; /* * */ const clog = (text, chat) => { if(!text.startsWith("- ")) { text = "LoTR5e: " + text; } let time = new Date(); let timeStr = ("0" + time.getHours()).slice(-2) + ":" + ("0" + time.getMinutes()).slice(-2) + ":" + ("0" + time.getSeconds()).slice(-2); log(timeStr + ": " + text); if(chat) { sendChat("LoTR5e", `/w "${whoAMI}" ${text}`); } }; /* * */ const chatMessage = (msg) => { if(msg.type === 'api') { const args = msg.content.split(/\s+/); if (args[0].toLowerCase() === '!lotr5e') { log("chatMessage: " + args); whoAMI = (getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); if (args[1].toLowerCase() === 'info') { sendChat("LoTR5e", "/w " + whoAMI + " pathlength, fp_change, fp_setmax, fp_reset"); } else { clog("Invalid command!", true); } } } }; /* * Event handling callbacks */ const registerEventHandlers = () => { on('chat:message', chatMessage); clog("Ready"); }; /* * Object 'methods' to return */ return { RegisterEventHandlers: registerEventHandlers }; })(); /* * Runtime */ on('ready', LoTR5e.RegisterEventHandlers ); Usually a conflict between scripts will be either both changing some global variable (you aren't doing that), or mutating the `msg` object passed the chat:message  event (you aren't doing that either), so I'm a bit stumped without trying them.
1707943111
Coryphon
Pro
Sheet Author
Thanks very much, I’ll take your versions and try them… ~ C ~