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

Change token tint color without selecting token

February 06 (4 years ago)

Hey everyone,

Is it possible to change a token's tint through character attributes, or some other way other than by first selecting the token? I am working on a board game that has multiple character tokens on the map layer, and I'd like to change the tint color during the game without having to select them individually. Specifically, if I have a token for a territory and it changes hands, I'd like to change the 'Owner' attribute from "Red Player" to "Blue Player" and have the tint match the change. I realize this is probably a stretch, but wanted to ask. 

If this isn't possible, does anyone know of an existing macro that might do something similar?

Thanks,



February 06 (4 years ago)

You might want to look at TokenMod. I think you could do this, you would need to know the token_id.

February 06 (4 years ago)
The Aaron
Roll20 Production Team
API Scripter

As Al e. said, you can do that via TokenMod. If you assign the tokens to represent a character, you can use the character ID to affect them:

!token-mod --set tint_color|#f00 --ids @{Germany|character_id} --active-pages --ignore-selected

Something along those lines. 

February 06 (4 years ago)

You guys are amazing. i will check this out!

February 06 (4 years ago)

It works like a charm! I decided to use token ID instead of character ID, since I don't think I'll need a character for each province (I think I can do what I need to on generic tokens).

This is what I'm using to change the tint color and bar2 value:

!token-mod --set tint_color|#ff0000 bar2_value|Red --ids -MSrzd4dddVceRIAQ9Bw --active-pages --ignore-selected

Before:

After:


Here's a follow-up question: I have a lot of provinces and six colors to map for each. It's going to be something like 450 separate macros if I build separate ones like above. Is there any way to organize or sort the macro folder if I do build that many? Do you have other suggestions? Maybe have the macro prompt the user for the color? Thanks for any ideas, and thanks again for pointing me in the right direction!

February 06 (4 years ago)
David M.
Pro
API Scripter

You didn't want to select the tokens, but what about using @{target|token_id}? 450macros is untenable. I would think querying for the color and using target would be the way to go considering the scale of what you are talking about. Or actually one macro for each color (put them all on the macro bar) to reduce the amount of clicks. E.g. click "SetRed" macro, click target province.

February 06 (4 years ago)

I would create a single character sheet called "Province". 

Change all the tokens to 'Represents' the character "Province". 

On "Province", create an ability TokenMod macro for each of the 6 colors that is named the color you want to change that token, e.g. Red, Blue, Green, etc. and make sure to check the 'Token Action' button so they display when you click on the token. You'll want to use '@{selected|token_id} for the --ids.

!token-mod --set tint_color|#ff0000 bar2_value|Red --ids @{selected|token_id} --active-pages

Then you simply need to click on the token, the 6 color Token Actions will show up, and you click on the name of the color you want to change the province.  

I know this goes against what you were asking for in your original post, but it would be far fewer clicks than creating 450 separate macros for 75 different territories, or building a huge query (my next suggestion below).


Another option would be to build a query for the color and territory name. That would be a single macro that would take a little bit to build, but it would be static, and only require 3 clicks if the tint color and bar2 value are the same:

!?{Color?|Red,#ff0000|Green,#00ff00|Blue,#0000ff}
!?{Province?|Awa,-MSrzd4dddVceRIAQ9Bw|Awaji,-MSrzd4dddVceRIAQ9Bx|Bizen,-MSrzd4dddVceRIAQ9By}
!token-mod --set tint_color|?{Color?} bar2_value|?{Color?} --ids ?{Province?} --active-pages --ignore-selected
You'd have to add all 6 colors (I only included 3, but hopefully that shows that it would look like) and all 75 territories and their individual Token IDs (I just faked those as well). If your tint color and Bar2 color are different, you could add a 3rd query to distinguish between the two.
February 06 (4 years ago)

Thank you David and Jarren! I am always amazed by the helpful posts I get on these forums. You folks rock!

All of these are great options for me. I think I will stick with changing by Token for now with a handful of macros, but will look into the 'big query' option in the future.

I have one last question for now. I'd like to have a macro that resets all bar2 values to "none" and all tints to transparent. Is that possible without first selecting all of the tokens? It would be ideal if I could launch the macro without switching to the map layer and selecting everything, since I often move stuff inadvertently when doing so :) Thanks if you have any other thoughts!


February 06 (4 years ago)
David M.
Pro
API Scripter

I think you'd have to pass all the ids to be able to do that. I'm not aware of an "all on current page" option. But, you could easily just click on the map, press Ctrl-A to select all, then run your token-mod reset macro using selected instead of ids. 

February 06 (4 years ago)

Taliesin said:

I have one last question for now. I'd like to have a macro that resets all bar2 values to "none" and all tints to transparent. Is that possible without first selecting all of the tokens? It would be ideal if I could launch the macro without switching to the map layer and selecting everything, since I often move stuff inadvertently when doing so :) Thanks if you have any other thoughts!

David M. said:

I think you'd have to pass all the ids to be able to do that. I'm not aware of an "all on current page" option. But, you could easily just click on the map, press Ctrl-A to select all, then run your token-mod reset macro using selected instead of ids. 

Yeah, you'd have to pass all the IDs to TokenMod, and selecting all the tokens on the layer of the page would work, unless there are other tokens on the layer that you don't want to adjust the Bar2 and tint for.

You could consider taking the time to get all the token IDs in a separate text file somewhere, so if you needed to post them all at once into a macro. That will take a bit of upfront work, but could save you time on the fly.

I'd also suggest using the MapLock script, so you can set tokens and lock them in place to prevent accidentally moving them! It's saved me on a few maps several times!

February 06 (4 years ago)
David M.
Pro
API Scripter

I was just coming here to suggest MapLock for Taliesin, haha!

February 06 (4 years ago)

Once again, thank you folks! The help is amazing.

February 07 (4 years ago)

The project has really been coming along! We put together the large query with all the province token IDs and it does run. I just have one (I hope) final question on this. Is it possible for the bar2_value be set to the input color (ie "Red") rather than the hex code (ie #ff8080)? I use another script to report out how many provinces are owned by each player, which reports the bar2 value and the number of provinces. It would be so much easier to read that table if the input value was copied to the bar2 value!

Again, thanks!!


!?{Color?|Red,#ff8080|Green,#c0ffc0|Blue,#95ceff|Orange,#ffbf80|Purple,#d991ff|Clear,transparent}

!?{Province?|Aki,-MStcnI-YNAwcU6Uu_du |Awa_North,-MSsujxckXJbsaUrefla |Awa_South,-MSu-MWNCN_48azS5riC |Awaji,-MSsuuxOMYdJ_0pHmLT6 |Bingo,-MSthQLqowzn2M5vyM59 |Bitchu,-MSthQxo1g4ncxgqSw3i |Bizen,-MSthRga1rjw-rSM5haX |Bungo,-MSt2ZBGiHPGRwjMH1Lw|Buzen,-MSt2TOVDU3MXcFXq-W2 |Chikugo,-MSt2fx4plGb_bQ_oOdU|Chikuzen,-MSt9Yv81jTfmcfTU27G |Dewa,-MSu1AOyzU7cSffGiIsh |Echigo,-MSu1BW0mib811Wp42N0 |Echizen,-MStpw2T95NoJH15LJAI |Etchu,-MStr9JQbSG2lRRBDe5N |Harima,-MSthT8UcpT2reQXiMS0 |Hida,-MStr8Gj0AO4twJMmo0Y |Higo,-MSt2zOv7yrN-VY4j4hp |Hitachi,-MSu-cppFq9-ELbS1xZj |Hizen,-MSt2bzz2z8faWFwLK6h |Hoki,-MStiGF52hu7RaRj-x2M |Hyuga,-MSt331PH17E9vS_w2ex |Iga,-MStuM6XS74c3Yk6ygND |Iki,-MSt2PjtKHy9OuB39pXy |Inaba,-MStiGtP2wC_u5nquqRF |Ise,-MStuJmnRW_ZSJ7KV3c_ |Iwami,-MStea_9aSXHZstOx52g |Iyo,-MSt9ap3PldhRqZdyKv1 |Izu,-MSu-HSREaOjvrUu37o9 |Izumi,-MStsYApq08Q3Pynw45h |Izumo,-MStebbEZAsesBr3UcfR |Kaga,-MStr5_Jk13biTO5YJOs |Kai,-MSu-aXkily419MyBzVU |Kawachi,-MStsWnAk4k83Uaw--_5 |Kazuka,-MStxqod2-5KBFAHoe3N |Kii,-MStsYnULJSFA4uGQXt8 |Kozuke,-MSu19jFfGV95mIVewPP |Mikawa,-MStvln8N20Jq_7agEPC |Mimaska,-MStiZVrVELxBqVqyr2m |Mino,-MStrA30QxB5bM-5_UlB |Musashi,-MStxssSb6_B4h8ZB8kz |Mutsu,-MStxru-ceZFqqh6VeZS |Nagato,-MStaRrOFlN-hDo3Hnkz |Noto,-MStr7USAjXcJ8eaBxxC |Oki,-MStaTfBU5q9yktcn1NE |Omi,-MStpwgP7kheR14i0D5Z |Osumi,-MSt3D4b95DloxBWic_J |Owari,-MStvjkHhJKwXGFPTMx3 |Sado,-MSu2lxBZj7ABXA2oTdi|Sagami,-MStvilEQLkO4w1QG7sy |Sanuki,-MSstxbaXckSnE4M62hP |Satsuma,-MSt38r7Tf6hxwaThQO4 |Settsu,-MStoJGKBM0iKc8ZK-eo |Shima,-MStsXWXddq8faEYKutv |Shimosa,-MStxtUZG7Xmi8tAeLwq |Shimotsuke,-MSu-bx5mmNRaiT8zIA7 |Shinano,-MSu1CBze7-Gxr86yxFm |Suo,-MStbbR_vlqcBIuCbBfU|Suruga,-MStvhIGr6eJinssFtOc |Tajima,-MStiHgdx8Sw4Jq1v4AS |Tamba,-MStoKfQkhl_wlLfCHH1 |Tango,-MStoJv4Ji8TGLx--Oxl |Tosa,-MSsulwJxFh4mE01L8i9 |Totomi,-MStvhweC5QbZR9uPBOJ |Tsushima,-MSt-B2WyTF059RjEeEy|Wakasa,-MStpvGNWIuKkObeq9ob |Yamashiro,-MStpxR99Fud2wKZNxqF |Yamato,-MStuJ41BawmYcvzy82f}

!token-mod {{
   --set tint_color|?{Color?} 
     bar2_value|?{Color?} 
   --ids ?{Province?} 
   --active-pages 
   --ignore-selected
}}
February 07 (4 years ago)

Edited February 07 (4 years ago)
David M.
Pro
API Scripter

If you install the new Scriptcards script (it's the successor to Powercards), we can re-use the query values and use conditionals to set a color text string which can then be used as input to token-mod.


!scriptcard {{
  --#hideCard|True

  --:Initialize String Vars|
      --&ColorHex|+?{Color?|Red,#ff8080|Green,#c0ffc0|Blue,#95ceff|Orange,#ffbf80|Purple,#d991ff|Clear,transparent}
      --&Province|+?{Province?|Aki,-MStcnI-YNAwcU6Uu_du |Awa_North,-MSsujxckXJbsaUrefla |Awa_South,-MSu-MWNCN_48azS5riC |Awaji,-MSsuuxOMYdJ_0pHmLT6 |Bingo,-MSthQLqowzn2M5vyM59 |Bitchu,-MSthQxo1g4ncxgqSw3i |Bizen,-MSthRga1rjw-rSM5haX |Bungo,-MSt2ZBGiHPGRwjMH1Lw|Buzen,-MSt2TOVDU3MXcFXq-W2 |Chikugo,-MSt2fx4plGb_bQ_oOdU|Chikuzen,-MSt9Yv81jTfmcfTU27G |Dewa,-MSu1AOyzU7cSffGiIsh |Echigo,-MSu1BW0mib811Wp42N0 |Echizen,-MStpw2T95NoJH15LJAI |Etchu,-MStr9JQbSG2lRRBDe5N |Harima,-MSthT8UcpT2reQXiMS0 |Hida,-MStr8Gj0AO4twJMmo0Y |Higo,-MSt2zOv7yrN-VY4j4hp |Hitachi,-MSu-cppFq9-ELbS1xZj |Hizen,-MSt2bzz2z8faWFwLK6h |Hoki,-MStiGF52hu7RaRj-x2M |Hyuga,-MSt331PH17E9vS_w2ex |Iga,-MStuM6XS74c3Yk6ygND |Iki,-MSt2PjtKHy9OuB39pXy |Inaba,-MStiGtP2wC_u5nquqRF |Ise,-MStuJmnRW_ZSJ7KV3c_ |Iwami,-MStea_9aSXHZstOx52g |Iyo,-MSt9ap3PldhRqZdyKv1 |Izu,-MSu-HSREaOjvrUu37o9 |Izumi,-MStsYApq08Q3Pynw45h |Izumo,-MStebbEZAsesBr3UcfR |Kaga,-MStr5_Jk13biTO5YJOs |Kai,-MSu-aXkily419MyBzVU |Kawachi,-MStsWnAk4k83Uaw--_5 |Kazuka,-MStxqod2-5KBFAHoe3N |Kii,-MStsYnULJSFA4uGQXt8 |Kozuke,-MSu19jFfGV95mIVewPP |Mikawa,-MStvln8N20Jq_7agEPC |Mimaska,-MStiZVrVELxBqVqyr2m |Mino,-MStrA30QxB5bM-5_UlB |Musashi,-MStxssSb6_B4h8ZB8kz |Mutsu,-MStxru-ceZFqqh6VeZS |Nagato,-MStaRrOFlN-hDo3Hnkz |Noto,-MStr7USAjXcJ8eaBxxC |Oki,-MStaTfBU5q9yktcn1NE |Omi,-MStpwgP7kheR14i0D5Z |Osumi,-MSt3D4b95DloxBWic_J |Owari,-MStvjkHhJKwXGFPTMx3 |Sado,-MSu2lxBZj7ABXA2oTdi|Sagami,-MStvilEQLkO4w1QG7sy |Sanuki,-MSstxbaXckSnE4M62hP |Satsuma,-MSt38r7Tf6hxwaThQO4 |Settsu,-MStoJGKBM0iKc8ZK-eo |Shima,-MStsXWXddq8faEYKutv |Shimosa,-MStxtUZG7Xmi8tAeLwq |Shimotsuke,-MSu-bx5mmNRaiT8zIA7 |Shinano,-MSu1CBze7-Gxr86yxFm |Suo,-MStbbR_vlqcBIuCbBfU|Suruga,-MStvhIGr6eJinssFtOc |Tajima,-MStiHgdx8Sw4Jq1v4AS |Tamba,-MStoKfQkhl_wlLfCHH1 |Tango,-MStoJv4Ji8TGLx--Oxl |Tosa,-MSsulwJxFh4mE01L8i9 |Totomi,-MStvhweC5QbZR9uPBOJ |Tsushima,-MSt-B2WyTF059RjEeEy|Wakasa,-MStpvGNWIuKkObeq9ob |Yamashiro,-MStpxR99Fud2wKZNxqF |Yamato,-MStuJ41BawmYcvzy82f}
--:Set Chosen ColorName by calling functions| --?[&ColorHex] -inc #ff8080|>SetRed --?[&ColorHex] -inc #c0ffc0|>SetGreen --?[&ColorHex] -inc #95ceff|>SetBlue --?[&ColorHex] -inc #ffbf80|>SetOrange --?[&ColorHex] -inc #d991ff|>SetPurple --?[&ColorHex] -inc transparent|>SetClear --:Make api call|

--@token-mod| _set tint_color|[&ColorHex] bar2_value|[&ColorName] _ids [&Province] _active-pages _ignore-selected

--X|End Macro

--:FUNCTIONS| --:SetRed| --&ColorName|Red --<| --:SetGreen| --&ColorName|Green --<| --:SetGreen| --&ColorName|Green --<| --:SetBlue| --&ColorName|Blue --<| --:SetOrange| --&ColorName|Orange --<| --:SetPurple| --&ColorName|Purple --<| --:SetClear| --&ColorName|Clear --<| }}
February 07 (4 years ago)

I really appreciate this! I have loaded Scriptcards and the macro you put together launches and prompts for color and province name. Unfortunately the province properties aren't changing. I will try to dig into this, and thanks for getting me this far!

February 07 (4 years ago)
David M.
Pro
API Scripter

I'd try either hardcoding one of the province ids in the token-mod call, or skipping it altogether using selected (just for troubleshooting purposes).

  --:Make api call|  
  --@token-mod| _set tint_color|[&ColorHex] bar2_value|[&ColorName] _ids @{selected|token_id}

You haven't made new instances of the tokens, have you? That would change the token_ids and mess up your epic province query.

February 12 (4 years ago)

Edited February 12 (4 years ago)

Hi there, thanks again for your guys help with this. I feel I'm close but am struggling a bit. Thanks if you have time to help troubleshoot, but I completely understand if you don't.

The token_ids are all the same, and the original macro suggested at the top of this thread still works.

I replaced the token-mod call in David's latest code with this for testing:

  --:Make api call|  
 --@token-mod| _set tint_color|[&ColorHex] bar2_value|[&ColorName] _ids @-MStcnI-YNAwcU6Uu_du

That ID is valid. The macro ran, but the province didn't change properties. I also tried it with the id in brackets, but same result. Is there a better syntax I should be using there? 

If you'd like to pop into the game and check it out (it is otherwise complete and looks great), just drop me a DM.

Thanks again!