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

[Script Update] TokenMod -- An interface to adjusting properties of a token from a macro or the chat area.

1618326031
The Aaron
Roll20 Production Team
API Scripter
Ok, that's definitely not desirable behavior.  I've duplicated it in testing, I'll get that fixed, thanks for finding it! The root issue is that they appear to have changed the way they are storing lowlight, so that breaks all the scripts that were working with low light on UDL.
1618326771

Edited 1618326998
I think i found my mistake. I was thinking the wrong way. Bright and Low Light a both measured from the center of the selected token, therefore the low light value has to be  higher than the bright light. So if i set bright on 40ft and low also on 40ft there isn't any low light beyond the bright. If i set bright on 40 ft and low on 60 ft there will be 20 ft low light beyond the brigth light. I was irritated by the "Total light" value at the bottom wich implies a larger field wich is lighten than it is actually. From your answer i read, that that also new for you. Thanks again for reading and assist (and for the script :-) ).
1618327070
The Aaron
Roll20 Production Team
API Scripter
No, I think you're right, the behavior has definitely changed.  I verified it by looking at the underlying values the UI creates vs what I'm storing with the API.  When UDL support first came out, the UI reflected the additional distance low light extends beyond bright light.  That is still the case.  However, the underlying data model stored the low light as the sum of bright light and lowlight distance.  That caused the need for additional calculation within API scripts to both do the addition to store the value AND adjust the value when changing bright light in the API.  At some point since, they've changed the data model to where the low light value stored is now the value in the UI without the need to adjust it based on bright light. It's a fantastic change, but it breaks every UDL script dealing with low light, which is a bit annoying.  I'll be going through my scripts and updating all the logic handling low light tonight.
1618327816
The Aaron
Roll20 Production Team
API Scripter
Actually, on further consideration and testing, Ignore the UI's output, the API is doing things correctly, the UI is broken.  The devs have been informed of the bug.
1618328188

Edited 1618328227
Yes, it works. I just looked at the UI and not on the actual token behaviour before.
1618516433
The Aaron
Roll20 Production Team
API Scripter
The UI is fixed now, so it should reflect what you're setting with TokenMod.
Yep, it is working now.
Trying to post and I get a the page you are trying to reach does not exist, or some such thing. 
Bob DM S. said: Trying to post and I get a the page you are trying to reach does not exist, or some such thing.  This worked. The post is long with multiple images. Failed twice. Hmmm.... 
1618592826
The Aaron
Roll20 Production Team
API Scripter
Hmm... Try it without the images, then edit it to add them maybe?  There is some limit to the size a post can be, maybe try splitting it into several posts?
1618592878
The Aaron
Roll20 Production Team
API Scripter
Also, if you're just copy/pasting it from some other editor, you need to manually type something, or it might not detect the content you pasted in.
I am having some issues with the UDL Directional Lighting. I have some macro using TokenMod that change the lighting. For this example I will use three. Snuff, turn everything off !token-mod --off emits_bright_light emits_low_light --set directional_bright_light_center#0 directional_bright_light_total#0 Torch, torch lighting !token-mod --on emits_bright_light emits_low_light --off has_directional_bright_light has_directional_dim_light --set bright_light_distance#20 low_light_distance#20 directional_bright_light_center#0 directional_bright_light_total#0 Bull, Bullseye lantern !token-mod --on emits_bright_light has_directional_bright_light --off emits_low_light --set bright_light_distance#120 low_light_distance#60 directional_bright_light_center#90 directional_bright_light_total#10   Everything works fine, unless I set the directional lighting Manually. I have Night Vision on with a tint of magenta to help show the lighting. Start with everything off. Bull works Bull works Can use the macros to change between then without issue. If I go in and manually set the Directional Lighting the macros fail.   This works as expected.  The bull macro works.   Snuff works Torch does not work. It reverts back to the manual directional settings.   Look at the settings manually and Directional Lighting is off.   Enable it and it is set to zero and zero.   Where is Roll20 getting the directional settings. Where is this stored that TokenMod is not changing it. Why is it still using the settings of 10 and 20?  If I just use save on the above settings, it saves the zero and zero directional settings. Now the Bull macro works, but if I use the torch, there is no light, because direction is set to Zero and zero, it is like Snuff. Try all the macros and nothing will correct this.  To clear this issue, I have to go into the settings manually and turn off lighting and save it. Then everything is "reset" and the macros work again. 
1618598096
The Aaron
Roll20 Production Team
API Scripter
Hmm. I will have to try and duplicate this. 
Like the others, I have been playing with Torches :D I have Three Macro's, and they are Sort of working. !## Turn off Torch !token-mod --set emits_bright_light|false !token-mod --set emits_low_light|false !token-mod --set aura1_radius|0 !## Turn on Torch !token-mod --set emits_bright_light|true !token-mod --set emits_low_light|true !token-mod --set aura1_radius|5 !## Narrow Lighting 80 Bright, 20 Low, 15 Deg !token-mod --set bright_light_distance|80 !token-mod --set low_light_distance|20 !token-mod --set directional_bright_light_total|15 !## Turn on Torch !token-mod --set emits_bright_light|true !token-mod --set emits_low_light|true !token-mod --set aura1_radius|5 !## Wide Lighting 30 Bright, 30 Low, 60 Deg !token-mod --set bright_light_distance|30 !token-mod --set low_light_distance|30 !token-mod --set directional_bright_light_total|60 I can see all the values changing, and the Light Distance is showing correct, as is the angle, but the angle is not updating. If I VIEW the angle by clicking on the cog, I can see that the macro is changing it back and forth between 60 and 15, but when I look at the pic, its stuck on the previous value. As soon as I click Save Settings, without changing anything, it then works. Am I Missing something? PS Thanks for before, I ignored the errors and kept on going and has been going well up until this point.
The Aaron said: Hmm... Try it without the images, then edit it to add them maybe?  There is some limit to the size a post can be, maybe try splitting it into several posts? I was copying screen shots and pasting directly into the chat and it would fail. What I ended up doing was to save the screen shots as files, then using the tool to insert the image from the file and it worked. 
1618766536
The Aaron
Roll20 Production Team
API Scripter
Gwar said: Like the others, I have been playing with Torches :D I have Three Macro's, and they are Sort of working. !## Turn off Torch !token-mod --set emits_bright_light|false !token-mod --set emits_low_light|false !token-mod --set aura1_radius|0 !## Turn on Torch !token-mod --set emits_bright_light|true !token-mod --set emits_low_light|true !token-mod --set aura1_radius|5 !## Narrow Lighting 80 Bright, 20 Low, 15 Deg !token-mod --set bright_light_distance|80 !token-mod --set low_light_distance|20 !token-mod --set directional_bright_light_total|15 !## Turn on Torch !token-mod --set emits_bright_light|true !token-mod --set emits_low_light|true !token-mod --set aura1_radius|5 !## Wide Lighting 30 Bright, 30 Low, 60 Deg !token-mod --set bright_light_distance|30 !token-mod --set low_light_distance|30 !token-mod --set directional_bright_light_total|60 I can see all the values changing, and the Light Distance is showing correct, as is the angle, but the angle is not updating. If I VIEW the angle by clicking on the cog, I can see that the macro is changing it back and forth between 60 and 15, but when I look at the pic, its stuck on the previous value. As soon as I click Save Settings, without changing anything, it then works. Am I Missing something? PS Thanks for before, I ignored the errors and kept on going and has been going well up until this point. BTW, it's more efficient to do these as a single command: !token-mod {{ --set emits_bright_light|true emits_low_light|true aura1_radius|5 bright_light_distance|80 low_light_distance|20 directional_bright_light_total|15 }} There's also a bug that can affect multiple API commands sent together to where some of the commands could get silently dropped.
Hi The Aaron, Thanks for a truely awesome script. I seem to have a small problem with a macro i'm making for the blinded condition i DnD 5e, I want to set the to off and nightvision to 5ft. that way the player can see their token and a bit of surrounding but not the rest of the vision range. I also want to set the light multiplier to 0 so that light sources don't reveal anything to this token. !token-mod --set has_bright_light_vision|off has_night_vision|on --set night_vision_distance|?{Distance?|5} --set light_multiplier|?{multiplier?|1} first 2 --set works as intended but the light_multiplier i cant get to change. What do i do wrong? :) 
1619136194
The Aaron
Roll20 Production Team
API Scripter
light_multiplier is for Legacy Dynamic Lighting, not Updated Dynamic Lighting.  A lot of people will set has_limited_field_of_vision on and  limit_field_of_vision_total to 0 for blindness.  That lets you see just your token, but nothing else.  Would need to do that with night vision also if that matters for a character.
The Aaron said: light_multiplier is for Legacy Dynamic Lighting, not Updated Dynamic Lighting.  A lot of people will set has_limited_field_of_vision on and  limit_field_of_vision_total to 0 for blindness.  That lets you see just your token, but nothing else.  Would need to do that with night vision also if that matters for a character. oh ok. Thanks :) and thanks for quick reply
1619137802
The Aaron
Roll20 Production Team
API Scripter
No problem!
Is there a way to set non numerical values in token bars? I like to put labels in some of my max values, but when I try setting them via TokenMod like this !token-mod --set bar2_max|0(temp) bar3_max|3(hero) the parentheses and text are ignored.
1619246233
The Aaron
Roll20 Production Team
API Scripter
Try putting the value in quotes?
1619279109
The Aaron
Roll20 Production Team
API Scripter
Hmm.. That should work but didn't.  Looking into it...
1619281477
The Aaron
Roll20 Production Team
API Scripter
Ok, found the issue, deploying a fix for it shortly.
1619282931
The Aaron
Roll20 Production Team
API Scripter
Update v0.8.65 -- Fixed text fields that start with a number getting truncated to only that number. (Thanks  Persephone )
Quick question: Does anyone have the TokenMod code to set "darkvision" on a token? The closest I've found is to set the night vision distance to 60, tint color to black, and night vision effect to "dimming" to start at 1. But, from what I can tell, the night vision effect setting isn't available in tokenmod (yet?).  BTW, the system keeps resetting the 1 to 5 and it does make a difference - I prefer setting it to 1 though. Yet another bug with UDL... But what are people using for "darkvision"? Thanks.
Thanks for the quick fix Aaron!
1619331235
The Aaron
Roll20 Production Team
API Scripter
Saul, Night Vision Effect is not exposed yet, but I have it on good authority that it's coming soon. Can you give an example of the command you're using to set the value to 1, and what you do which ends up with it at 5?
Hey, I was wondering if someone could help me with a problem. I want to make a macro so that my players can activate and deactivate a flashlight. The range for it is 30 ft bright, 30 ft dim and 53 degrees directional. I got the light radius figured out. But the directional bit doesn’t seem to work. My code is as follows: !token-mod {{   --on emits_bright   --set bright_light_distance|30   --on has_directional_bright_light   --set directional_bright_light_total|53   --on emits_low   --set low_light_distance|30   --on has_directional_low_light   --set directional_low_light_total|53 }} When I try it out it doesn’t do the directional light though. It does set and activate the light radius correctly but it doesn’t activate the directional effect. Light emits from Esir When I open their character settings it does say it has it turned on and it does set it to the right radius. But it only activates the radius once I save from that menu. After I press save settings it turns the light into the desired cone. Light emits from Braum after closing the settings and the macro can't change the radius. When the settings have been saved before it grabs the previous radius. For example I set Braum's radius previously and when I use that macro it works. But if I wanted to change the radius it wouldn't change it.  Thanks in advance!
1619378073

Edited 1619378268
The Aaron
Roll20 Production Team
API Scripter
This is a bug in the UDL implementation for API.  It's something Roll20 has to fix unfortunately. BTW, you need to be sure the {{ are on the same line as the ! for API Commands: !token-mod {{ --on emits_bright --set bright_light_distance|30 --on has_directional_bright_light --set directional_bright_light_total|53 --on emits_low --set low_light_distance|30 --on has_directional_low_light --set directional_low_light_total|53 }} Also, you can group the set's and on's: !token-mod {{ --on emits_bright has_directional_bright_light emits_low has_directional_low_light --set bright_light_distance|30 directional_bright_light_total|53 low_light_distance|30 directional_low_light_total|53 }}
Ah well, big sad with regards to the bug. thanks anyway.  I did the {{ wrong in the post but had them correct in the macro but thanks for the grouping. Makes it way clearer. I'm not really great with code so your posts always help.
1619379951
The Aaron
Roll20 Production Team
API Scripter
Something I really like about UDL is what I'm calling "Keyhole Lighting": I'm giving the token 5ft of night vision to give them just a bit of visibility around them.  To me, that feels a bit more realistic and visually pleasing. =D
Hello Master Aaron, A quick question and maybe an addition to TokenMod.  Is it possible to set the LoS to start at the edge of the Token instead of at the center? And can this be turned on/off by TokenMod? /X
1619439207
The Aaron
Roll20 Production Team
API Scripter
That isn't something the API has any control over. 
I'm having trouble using this simple call: !token-mod --flip bright_vision It toggles the Vision toggle in the UDL tab of the Token Settings .  And it makes the token "disappear" for the player on a UDL map. However, when flipping to the TRUE state, the player isn't seeing other tokens that are emitting light (like a torch on a wall). If I use the Roll20 Token Settings UI to toggle the flag instead of the token-mod call, it works just fine. I posted a short video on YouTube to help demonstrate. Roll20 TokenMod UDL Bug Repro Thanks for all your contributions!
1619442185
The Aaron
Roll20 Production Team
API Scripter
Unfortunately, that's a bug in UDL on Roll20's side that I can't do anything about.  I'll pass this on to them though as it's nice to have repro cases.
The Aaron said: Unfortunately, that's a bug in UDL on Roll20's side that I can't do anything about.  I'll pass this on to them though as it's nice to have repro cases. Thanks!
As it would appear others are having an issue with token-mod updating lighting with UDL, so too am I. !token-mod --set emits_low|yes emits_bright|yes light_radius#?{Value} light_dimradius#?{Value} aura1_radius#?{Value} showplayers_aura1|yes defaulttoken --report gm|"{name} now has dim light of {light_dimradius}ft and bright light of {light_radius}ft which is {aura1_radius}ft of sunlight." This sets the aura correctly, but otherwise doesn't change the light radii, despite reporting the supposed new value.
1619552052
The Aaron
Roll20 Production Team
API Scripter
The properties light_radius and light_dim_radius are for LDL.  You'd need to use the UDL properties.
Gah! Which one's are those?
1619615976
The Aaron
Roll20 Production Team
API Scripter
Check here:&nbsp;<a href="https://app.roll20.net/forum/permalink/9064542/" rel="nofollow">https://app.roll20.net/forum/permalink/9064542/</a>
Having a total brain failure.&nbsp; With all the talk about UDL, I don't thing Token Mod will set these values. What macro can be used to set the following values as given in this page. Can someone point me in the correct direction.&nbsp; <a href="https://help.roll20.net/hc/en-us/articles/360046490373-Updated-Dynamic-Lighting-API-Support#page-settings-0-3" rel="nofollow">https://help.roll20.net/hc/en-us/articles/360046490373-Updated-Dynamic-Lighting-API-Support#page-settings-0-3</a> Page Settings dynamic_lighting_enabled daylight_mode_enabled explorer_mode force_lighting_refresh
1619626165
The Aaron
Roll20 Production Team
API Scripter
Here's a small script for daylight: on('ready',()=&gt;{ const getPageForPlayer = (playerid) =&gt; { let player = getObj('player',playerid); if(playerIsGM(playerid)){ return player.get('lastpage') || Campaign().get('playerpageid'); } let psp = Campaign().get('playerspecificpages'); if(psp[playerid]){ return psp[playerid]; } return Campaign().get('playerpageid'); }; on('chat:message',msg=&gt;{ if('api'===msg.type &amp;&amp; /^!toggle-daylight(\b\s|$)/i.test(msg.content) &amp;&amp; playerIsGM(msg.playerid)){ let who = (getObj('player',msg.playerid)||{get:()=&gt;'API'}).get('_displayname'); let pid = getPageForPlayer(msg.playerid); let page = getObj('page',pid); let args = msg.content.split(/\s+/); let isSet = false; let setValue = true; if(args.length&gt;1){ isSet = true; setValue = ['on','yes','y','true','t'].includes(args[1].toLowerCase()) || ((parseInt(args[1])||0)&gt;1); } let field = ''; if(page.get('dynamic_lighting_enabled')) { field = 'daylight_mode_enabled'; } else if(page.get('showlighting')) { field = 'lightglobalillum'; } if(field) { let curr = page.get(field); setValue = (isSet ? setValue : !curr); if(setValue !== curr){ page.set(field, setValue); sendChat('',`/w "${who}" Daylight set to ${setValue ? 'On' : 'Off'}`); } } else { sendChat('',`/w "${who}" Dynamic Lighting not in use on this page.`); } } }); }); force_lighting_refresh is broken (possibly removed right now).&nbsp; I'll have to poke at the explorer_mode and dynamic_lighting_enabled settings.
Mille grazie!
This is very cool. Let me explain where I am coming from and what I want to do. I ran the convert to UDL program from Roll20. It did not do everything I thing it should have. Yes it turned off Advanced Fog of War and Dynamic Lighting in the LDL, but it did not uncheck the boxes for Show Grid, Dim Light Revels, Enforce Line of Sight, Only Update on Drop, Global Illumination. I feel these setting still being on, although the top level is off, might be part of the issues I have with UDL. I want to be able to run a scrip on the current page and flip all these off, not toggle them, and also enable in UDL Dynamic Lighting on, Explorer Mode on, Update when Token Drop on. Not toggle these, but enable these.&nbsp; So rather than open the page settings and "fix" all the standard settings, just run the script.&nbsp; I know just enough to be dangerous and will play with this script you gave us. :) Bob&nbsp; The Aaron said: Here's a small script for daylight: on('ready',()=&gt;{ const getPageForPlayer = (playerid) =&gt; { let player = getObj('player',playerid); if(playerIsGM(playerid)){ return player.get('lastpage') || Campaign().get('playerpageid'); } let psp = Campaign().get('playerspecificpages'); if(psp[playerid]){ return psp[playerid]; } return Campaign().get('playerpageid'); }; on('chat:message',msg=&gt;{ if('api'===msg.type &amp;&amp; /^!toggle-daylight(\b\s|$)/i.test(msg.content) &amp;&amp; playerIsGM(msg.playerid)){ let who = (getObj('player',msg.playerid)||{get:()=&gt;'API'}).get('_displayname'); let pid = getPageForPlayer(msg.playerid); let page = getObj('page',pid); let args = msg.content.split(/\s+/); let isSet = false; let setValue = true; if(args.length&gt;1){ isSet = true; setValue = ['on','yes','y','true','t'].includes(args[1].toLowerCase()) || ((parseInt(args[1])||0)&gt;1); } let field = ''; if(page.get('dynamic_lighting_enabled')) { field = 'daylight_mode_enabled'; } else if(page.get('showlighting')) { field = 'lightglobalillum'; } if(field) { let curr = page.get(field); setValue = (isSet ? setValue : !curr); if(setValue !== curr){ page.set(field, setValue); sendChat('',`/w "${who}" Daylight set to ${setValue ? 'On' : 'Off'}`); } } else { sendChat('',`/w "${who}" Dynamic Lighting not in use on this page.`); } } }); }); force_lighting_refresh is broken (possibly removed right now).&nbsp; I'll have to poke at the explorer_mode and dynamic_lighting_enabled settings.
@The Aaron, appending bar value changes with a ! to keep the value between 0 and max isn't working anymore. The bar is being set to that exact value rather than being modified. So this command !token-mod --set bar1_value|-11! is setting the value to -11! instead of subtracting 11. I'm guessing it's because of the changes you made to prevent characters following a number from being ignored.
1619934309
The Aaron
Roll20 Production Team
API Scripter
Hmm. I bet you're right. I'll take a look.&nbsp;
1st off I really apricate this script, the ability to automate setting up tokens is so powerful as a time saver and a cover against token sight issues. I do have one question: one of the options that roll20 provides is a standard vs compact bars; have I missed the commands to control this in token-mod? If it is not in the mod is this something even achievable within the API or is it hidden away and impossible to edit (I just don't really understand how powerful the API is)?
1619993862
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
That setting is one of several that have not yet been exposed to the API. This has been a request for something like two years(?).
Eric H. said: &nbsp;I do have one question: one of the options that roll20 provides is a standard vs compact bars; have I missed the commands to control this in token-mod?&nbsp; If it is not in the mod is this something even achievable within the API or is it hidden away and impossible to edit (I just don't really understand how powerful the API is)? keithcurtis said: That setting is one of several that have not yet been exposed to the API. This has been a request for something like two years(?). I have an open suggestion here from August, 2020 - the Bar Position and Styles were added just over two years ago. Feel free to upvote it if you want it to be implemented!