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

API to alter a Page's Dynamic LIghting settings?

I want to be able to turn Dynamic Lighting on and off via an API, is this possible?  Basically for the old Keep on the Borderlands, I want to try and use just one page.  When the players are above ground I want Dynamic Lighting disabled for the page, and when then go underground turn the Dynamic Lighting back on.  A bit of a pain to do it manually, but if I can't do it, ah well, I'll survive.
1591580537
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
As long as there are no light obstructions (walls) on the above ground portions, you can just surround that portion of the map with a DL rectangle and put in a single huge light source. No need to toggle DL.
Kieth, since it is one map layer with two map images, and one Dynamic Lighting layer, the DL will still trace out on the above ground map.  It will also block movement on the above ground map.  So I want to manipulate the settings for blocking movement as well as Global Illumination.
Maybe this works for you: on ( "ready" ,  function ()  {      on ( "chat:message" ,  function ( msg )      {          if  ( msg . type  ===  "api"  &&  playerIsGM ( msg . playerid ) &&  msg . content  ===  "!ToggleDL" )         {              const   pageID  =  Campaign (). get ( "playerpageid" )              const   page  =  getObj ( 'page' ,  pageID )              if (! page )             {                  sendChat ( 'toggleDL' ,  'No Page Found' )                  return             }              // change names to whatever names you give the graphic for the maps              // map1 should be your above ground map, map2, the one with Dynamic Lighting on              const   map1  =  findObjs ({ _type :   'graphic' ,  layer :   'map' ,  pageid :   pageID ,  name :   'map1' })[ 0 ]              const   map2  =  findObjs ({ _type :   'graphic' ,  layer :   'map' ,  pageid :   pageID ,  name :   'map2' })[ 0 ]                           if  ( page . get ( 'showlighting' ))             {                  if ( map1 )  toFront ( map1 )                  page . set ( "lightglobalillum" ,  true )                  page . set ( "showlighting" ,  false )             }              else             {                  if ( map2 )  toFront ( map2 )                  page . set ( "showlighting" ,  true )                  page . set ( "lightglobalillum" ,  false )             }         }     }) }) Probably could use zorder instead of naming maps, but you get all graphics that way, so.. pass. 
Bast L. awesome, thanks, I am going to try this out after work today.  If it works well I have other uses for it, like removing roof sections from a village map.  Now if there was a way to easily remove/add the LoS lines, I could see even more uses for things like this.  I haven't gone over to the test servers, but do you know if the API for the new Dynamic Lighting has been announced?  I like the way it functions more than the traditional, so am excited to see it come to play, though I have reverted to the traditional settings for my active games for now.
1591642199

Edited 1591642210
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Scott W. said: Kieth, since it is one map layer with two map images, and one Dynamic Lighting layer, the DL will still trace out on the above ground map.  It will also block movement on the above ground map.  So I want to manipulate the settings for blocking movement as well as Global Illumination. That's why I added the caveat that there are no obstructions on the above ground map. If there are no DL walls, there is nothing to block light or movement. If there are DL blockers, then hopefully Bast L's script will do the trick! As for your other question, Yes I believe that UDL has been exposed to the API, since Token-mod can set UDL settings. this was one of the first things the dev team did to ensure there would be no nasty surprises along the way.
1591642599
The Aaron
Roll20 Production Team
API Scripter
It is exposed.&nbsp; Here's details:&nbsp; <a href="https://roll20.zendesk.com/hc/en-us/articles/360046490373-Updated-Dynamic-Lighting-API-Support" rel="nofollow">https://roll20.zendesk.com/hc/en-us/articles/360046490373-Updated-Dynamic-Lighting-API-Support</a>
Bast L. said: Maybe this works for you:Probably could use zorder instead of naming maps, but you get all graphics that way, so.. pass.&nbsp; Ok, so this is working pretty good.&nbsp; The one issue that I see though is that the global illumination and disabling DL is applying before the toFront(map1), it just flashes quickly so it may not be a big issue, but definitely gives a quick look at the map.&nbsp; I tried to add a delay (along with some logging) but that did not do anything to change that quick view, here is the portion of the code with my added bits marked-&nbsp; if (page.get('showlighting')) { if(map1) toFront(map1) ---&gt; _.delay(log,2000,'Set map - Overland') page.set("lightglobalillum", true) page.set("showlighting", false) } else { if(map2) toFront(map2) ---&gt; log("Set map - Caves") page.set("showlighting", true) page.set("lightglobalillum", false) } }
The Aaron said: It is exposed.&nbsp; Here's details:&nbsp; <a href="https://roll20.zendesk.com/hc/en-us/articles/360046490373-Updated-Dynamic-Lighting-API-Support" rel="nofollow">https://roll20.zendesk.com/hc/en-us/articles/360046490373-Updated-Dynamic-Lighting-API-Support</a> Thanks Aaron!
1591672354

Edited 1591673203
Bast L.
API Scripter
Hmm, I had thought, after posting it, that I should change the order like: else { &nbsp;&nbsp;&nbsp;&nbsp; page . set ( "showlighting" ,&nbsp; true ) &nbsp;&nbsp;&nbsp;&nbsp; page . set ( "lightglobalillum" ,&nbsp; false ) &nbsp;&nbsp;&nbsp;&nbsp; if ( map2 )&nbsp; toFront ( map2 ) } But the lighting change happened for me first, with no flash of the map. Anyways, I don't know Underscore.js much, but setTimeout seems to work: if (page.get('showlighting')) { if(map1) toFront(map1) setTimeout(() =&gt; { page.set("lightglobalillum", true) page.set("showlighting", false) }, 500) } else { page.set("showlighting", true) page.set("lightglobalillum", false) setTimeout(() =&gt; {if(map2) toFront(map2)}, 500) } Edit: Looking at the Underscore.js documentation it can work. Your code above only delays logging though, it doesn't make the rest of the code await that logging. It's really just the same as setTimeout, as far as I can tell. if (page.get('showlighting')) { if(map1) toFront(map1) _.delay(() =&gt; { page.set("lightglobalillum", true) page.set("showlighting", false) }, 500) } else { page.set("showlighting", true) page.set("lightglobalillum", false) _.delay(() =&gt; {if(map2) toFront(map2)}, 500) }