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 .
×

[Scriptlet] Light Meter

Keith, I'm trying to use this scriptlet in a new game and it doesn't seem to be working. I had saved the code that you posted a year ago  to a text file. I copied that into a new script for my new game,  restarted the sandbox, and added the " **" to the end of a PC token's name, but no icon shows up when I move the token into different light levels. I did try both the Default and Experimental sandboxes. Does this scriptlet not work with the new VTT? I found the old forum post and tried going to the github link you provided, checking if you had posted an updated version but that link gets me a "404 Not found" error. Here is the script that I saved: on("change:graphic", function(obj, prev) { let tokenID = obj.get("id"); let page = getObj("page", Campaign().get("playerpageid")); if (typeof checkLightLevel !== "undefined" && page.get("dynamic_lighting_enabled")) { if (prev.left !== obj.get("left") || prev.top !== obj.get("top")) { function containsIllumination(illumination, obj) { return illumination.some(item => obj.name.includes(item)); } function updateIllumination(obj, lightLevel, dimLight, darkness) { let newName; if (lightLevel <= darkness) { newName = obj.name.slice(0, -3) + " 🌑"; } else if (lightLevel > darkness && lightLevel <= dimLight) { newName = obj.name.slice(0, -3) + " 🌗"; } else { newName = obj.name.slice(0, -3) + " 🌕"; } return newName; } let dimLight = 50; let darkness = 20; let lightLevel = (checkLightLevel.isLitBy(obj.get("id")).total * 100).toFixed(); let illumination = [" **", " 🌑", " 🌗", " 🌕"]; if (containsIllumination(illumination, prev)) { let newName = updateIllumination(prev, lightLevel, dimLight, darkness); obj.set("name", newName); } } } });
1773776225

Edited 1773776438
Pak
Pro
Hi Rick. I can confirm the original script still works for me. I'm using latest VTT (Jumpgate) as well as beacon character sheets.  I tried to eyeball my copy of the code against yours and they appear to match except for the missing full moon, half moon, and new moon emojis on your code. Not sure if it matters but did you swap out the icons with the appropriate emojis? My copy of the code below: on("change:graphic", function(obj, prev) {     let tokenID = obj.get("id");     let page = getObj("page", Campaign().get("playerpageid"));     if (typeof checkLightLevel !== "undefined" && page.get("dynamic_lighting_enabled")) {         if (prev.left !== obj.get("left") || prev.top !== obj.get("top")) {             function containsIllumination(illumination, obj) {                 return illumination.some(item => obj.name.includes(item));             }             function updateIllumination(obj, lightLevel, dimLight, darkness) {                 let newName;                 if (lightLevel <= darkness) {                     newName = obj.name.slice(0, -3) + " ";                 } else if (lightLevel > darkness && lightLevel <= dimLight) {                     newName = obj.name.slice(0, -3) + " ";                 } else {                     newName = obj.name.slice(0, -3) + " ";                 }                 return newName;             }             let dimLight = 50;             let darkness = 20;             let lightLevel = (checkLightLevel.isLitBy(obj.get("id")).total * 100).toFixed();             let illumination = [" **", " ", " ", " "];             if (containsIllumination(illumination, prev)) {                 let newName = updateIllumination(prev, lightLevel, dimLight, darkness);                 obj.set("name", newName);             }         }     } }); Below is a pic from showing the code with emojis. You can see the 4 lines that require the emojis
Hmm. Mine looks the same. Here is a pic from the MODs page showing the code with the emojis. The only change I made is to add the annotation at the top:
Do you have the “checkLightLevel” script installed? It is a prerequisite.
1773791396
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
That's about the only advice I have here. If checkLightLevel is installed and it's still not working, we can investigate further.
Yes, CheckLightLevel is loaded. Here is a screen shot showing my currently loaded MODS: Here is a screen shot showing the character token for Grumm ** with the token menu open. In the sidebar is the output from when I typed !checklight  to verify that CheckLightLevel was working:
Only things I can think of to try (if you haven't done these already) is to make sure dynamic lighting is on for the page, and that it's the page with the player ribbon.
1773846302

Edited 1773850928
Pak
Pro
Rick. Did you try moving the token after you change the name (after adding the " **")? When I make the name change, the moon phase icon does not show immediately. It only shows the " **". But once I move the token to an adjacent cell, the " **" changes to the appropriate moon phase.
1773849128
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Rick, if you want to PM me an invite, I'd be happy to come take a look.
That was it! I don't always put the player ribbon on the maps when I'm setting up encounters or trying things out in case one of my players pops in to access their character sheet or one of the player-editable handouts that I gave them. Once I moved the player ribbon to the page, everything now works. I'll have to add a note about that to the annotation I put at the start of the script. Jim R. said: ... and that it's the page with the player ribbon.
1773855950
timmaugh
Pro
API Scripter
If you ever need to check the light hitting a token (as a matter of troubleshooting or for adjusting the math of a roll, etc.), the MetascriptToolbox has incorporated the checkLightLevels script: @(<token reference>.checklight_total) @(<token reference>.checklight_isbright) ...where "<token reference>" can be any of: selected a token ID, available as... hard-coded returned via Roll20 @{selected|token_id} construction, or returned via Roll20 @{target|token_id} construction a token name checklight_total  will return a value between 0 and 1 for the amount of light hitting the token.  checklight_isbright  will return 'true' or 'false' to represent whether the token is in bright light.
1773875636
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Rick A. said: That was it! I don't always put the player ribbon on the maps when I'm setting up encounters or trying things out in case one of my players pops in to access their character sheet or one of the player-editable handouts that I gave them. Once I moved the player ribbon to the page, everything now works. I'll have to add a note about that to the annotation I put at the start of the script. Jim R. said: ... and that it's the page with the player ribbon. Derp. I'm not batting particularly high this week.