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

[Help/Request] Sudden Darkness?

1462217507

Edited 1462221860
Havoc
Sheet Author
API Scripter
Let's say I want to create an effect of "flickering light" that makes the whole map dark for a second and back again, to be dark once more. In some kind of loop. The question is how do I do this? It must be not only possible when tokens are on the page (dungeon), but also where there's nothing (just a picture). I would guess something with Fog of War? Or make a giant black token (or painting)? Maybe someone already did this? EDIT: Done. Macro : !suddendark ?{ms|2000} ?{flicker?|Yes,true|No,false} ?{times?|10} Explanation : 1st Argument is interval in miliseconds. 2nd Argument is if it's going to flicker (times should be also set) or only one time darkness 3rd Argument is how many times it will flick on/off. Code : var suddenDarkness = false; function SuddenDarkness(interval, flicker, times) {     if (interval == null) interval = 200;     if (flicker == "false") flicker = false;     else flicker = true;     if (times == null) times = 0;     if (times % 2 == 1) times = times + 1;          if (suddenDarkness == false)     {                 var currentPage = findObjs({                                           _id: Campaign().get("playerpageid"),                                           _type: "page"                                      })[0];         currentPage.set("showlighting", true);         currentPage.set("lightglobalillum", false);         if (flicker == true)         {             var i = 0;             var inter = setInterval(function()             {                 currentPage.set("lightglobalillum", !currentPage.get("lightglobalillum"))                   i = i + 1;                 if (i == times)                 {                     currentPage.set("lightglobalillum", true);                     currentPage.set("showlighting", false);                     clearInterval(inter);                 }             }, interval)                     }         else         {                 setTimeout(function()                 {                     currentPage.set("lightglobalillum", true)                 }, interval);         }          suddenDarkness = false;     } }; on("chat:message", function(msg) {     if ( msg.type != 'api' ) return;     var cmd = msg.content.toLowerCase().split(' ');     if ( cmd[0] == "!suddendark" )      {         SuddenDarkness(cmd[1], cmd[2], cmd[3]);     } });
1462217890
The Aaron
Pro
API Scripter
You can't access Fog of War from the API.   On a page where you haven't done anything with Dynamic Lighting and no tokens have vision, you could turn on Dynamic Lighting and then turn off and on Global Illumination to get that effect.
1462218992

Edited 1462220518
Havoc
Sheet Author
API Scripter
Not good at JS. var suddenDarkness = false; function SuddenDarkness(interval, flicker, times) {     if (interval == null) interval = 200;     if (flicker == null) flicker = false;     if (flicker != false && flicker != true) flicker = false;     if (times == null) times = 0;          if (suddenDarkness == false)     {                 var currentPage = findObjs({                                           _pageid: Campaign().get("playerpageid"),                                           _type: "page",                                       });                      currentPage.set("showlighting", true);                  if (flicker == true)         {             for(var i = 0; i < times; i++)             {                 setTimeout(function()                 {                     currentPage.set("lightglobalillum", true)                   }, interval);                 currentPage.set("lightglobalillum", false);             }         }         else         {                 setTimeout(function()                 {                     currentPage.set("lightglobalillum", true)                 }, interval);                 currentPage.set("lightglobalillum", false);         }              currentPage.set("showlighting", false);         currentPage.set("lightglobalillum", false); suddenDarkness = false;     } }; on("chat:message", function(msg) {     if ( msg.type != 'api' ) return;     var cmd = msg.content.toLowerCase().split(' ');     if ( cmd[0] == "!suddendark" )      {         SuddenDarkness(cmd[1], cmd[2], cmd[3]);     } }); I get an error. So... yeah. How do you set timer/sleep here? TypeError: currentPage.set is not a function TypeError: currentPage.set is not a function at SuddenDarkness (apiscript.js:915:21) at Object.<anonymous> (apiscript.js:948:9) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:105:34), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:105:34), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1197:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) at Id.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:489) at Ld.Mb (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:94:425)
1462219424
Ada L.
Marketplace Creator
Sheet Author
API Scripter
findObjs returns a list. You'll need to do findObjs({...})[0] to get the page.
1462219682

Edited 1462221410
Havoc
Sheet Author
API Scripter
Yeah, my bad. But still this: findObjs({ _pageid: Campaign().get("playerpageid"), _type: "page", }) Gives me an empty table. What gives? EDIT: _id, not _pageid. D'oh!
1462221229
Havoc
Sheet Author
API Scripter
Done. Finished code is in the first post. Problem still is with, if the interval is too low (less than about 1 second), then the flickering doesn't happen as often. It is connected to changing the boolean, I think. Before it changes, the next interval steps up and reads the old value.
1462221531

Edited 1462221603
Ada L.
Marketplace Creator
Sheet Author
API Scripter
For dealing with intervals, you should use setInterval() instead of setTimeout. After it has flicked the number of times you want it to, then you need to clear the interval. It might be going slow though because it there is a delay to send the message to the server to turn global illumination on and off.
1462221891
Havoc
Sheet Author
API Scripter
Stephen L. said: For dealing with intervals, you should use setInterval() instead of setTimeout. After it has flicked the number of times you want it to, then you need to clear the interval. It might be going slow though because it there is a delay to send the message to the server to turn global illumination on and off. Thanks for the idea! Updated the code. Oh, right. The lag.