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

Token Mod - How to Set Nameplate for Names With Spaces?

December 11 (2 years ago)

Edited December 12 (2 years ago)

5e by Roll 20 sheet

I'm using this script to set up NPC tokens:

!token-mod {{

--set bar1_link|none

--set bar1|?{Enter HP Value|

Roll HP,[[@{selected|npc_hpformula}]]|

Custom HP,?{Custom HP Value}|}

--set name|{@selected|character_name}

--set bar2_link|ac

--set bar3_link|npc_speed

--off showplayers_bar1

--off showplayers_bar2

--off showplayers_aura1

--off showplayers_aura2

?{Name|No Name}

--set name|"?{Name}"

?{Show Name?|No, –off showplayers_name|Yes, --on showplayers_name|}

}}


It does what I want, except the --set name|{@selected|character_name} part is truncating names with spaces on the nameplate.  So my Brown Bear becomes Brown, my Assassin Vine becomes Assassin, and so on. I've seen some places where the answer was to use quotes, but I haven't been able to make that work.  If I leave that line out, it works fine but I'm interested in understanding what's happening here. 


The query for a custom name mostly does what I want, but it seems to lock the showplayers_name to on.  For example, I can run the script and it rolls hp, names the bear Chongo the Smart, and shows his name to the players.  But if I run the script again to hide name from players, it stays with the previous setting.  If I take out the name query, I can set showplayers_name to on or off as I choose. 


There are times when I don't want to use the character_name (if I'm understanding that correctly, and that's the "character represents" name) because I want my Brown Bear to be named Chongo The Smart, so I'd like to be able to both toggle the name on/off and be able to specify a custom name or use the standard name from the character sheet.  Is this possible?


For now, I'm removing the parts that are causing me issues, but I'd appreciate guidance/advice.

December 11 (2 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

HI Eponymous!

Oddly, you have the answer later on in the macro. Put it in quotes:

--set name|"{@selected|character_name}"

If that doesn't work (I only glanced at the macro), let me know and I'll take a deeper dive.

December 12 (2 years ago)


keithcurtis said:

HI Eponymous!

Oddly, you have the answer later on in the macro. Put it in quotes:

--set name|"{@selected|character_name}"

If that doesn't work (I only glanced at the macro), let me know and I'll take a deeper dive.


Thank you, Keith.  That solved a portion of it, and led me to an understanding about why I couldn't set the the --off showplayers_name:  Google Docs doesn't separate those two dashes, so instead of -- I had – which, you know, doesn't work.

That said, I can make it work now with query for a custom name OR using the sheet name, but I can't seem to get a query to give me the option of a custom name or the sheet name to work quite right.  I'm close with this:

!token-mod {{
--set bar1_link|none
--set bar1|?{Enter HP Value|
Roll HP,[[@{selected|npc_hpformula}]]|
Custom HP,?{Custom HP Value}|}
--set bar2_link|ac
--set bar3_link|npc_speed
--off showplayers_bar1
--off showplayers_bar2
--off showplayers_aura1
--off showplayers_aura2
--set name|?{Choose a Name|
Use Sheet Name,"@{selected|character_name}"|
Custom Name,?{Name|No Name}|"?{Name}"
?{Show Name?|No, --off showplayers_name|Yes, --on showplayers_name|}
}}

But it's not quite right. 

If I choose the "Use Sheet Name" option, I get the Brown Bear as expected. 

The custom name option is wonky, and I'm chasing my tail trying to figure it out:  I get offered "Custom Name" and "No Name".  Selecting "Custom Name" gives me a box to enter a name, and the box has "?{Name prepopulated.  If I type "Chongo the Smart", then my token is named Chongo.  If I select "No Name" from the query, I get a box to enter the name (with nothing in it).  I type in Chongo the Smart, and my token is named Chongo the Smart.

I'm sure there's a simple solution, but I know just enough to get myself in trouble here, so I'm asking for help!

December 12 (2 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Hmm. it could be the way that the query is resolved. The quote marks might not "persist" past their initial usage?

In any case, I'm having difficulty parsing the nested queries in --set name. What happens if you type "Chongo the Smart" but include the quotes while you are typing?

December 12 (2 years ago)


keithcurtis said:

Hmm. it could be the way that the query is resolved. The quote marks might not "persist" past their initial usage?

In any case, I'm having difficulty parsing the nested queries in --set name. What happens if you type "Chongo the Smart" but include the quotes while you are typing?


Using the "Custom Name" option in the query and typing "Chongo the Smart" does in fact work.





December 12 (2 years ago)
timmaugh
Forum Champion
API Scripter

Doesn't a nested query have to have all of its control characters HTML-escaped?

ALL => BECOME
|  => |
,  => ,
}  => }

But also, like Keith said, your nested queries are a little hard to parse. But, doing my best, I think this...

--set name|?{Choose a Name|
Use Sheet Name,"@{selected|character_name}"|
Custom Name,?{Name|No Name}|"?{Name}"
?{Show Name?|No, --off showplayers_name|Yes, --on showplayers_name|}

would become...

--set name|?{Choose a Name|
Use Sheet Name,"@{selected|character_name}"|
Custom Name,"?{Name|No Name}"} ?{Show Name?|No,--off showplayers_name|Yes,--on showplayers_name}

I think.


December 12 (2 years ago)


timmaugh said:

...

--set name|?{Choose a Name|
Use Sheet Name,"@{selected|character_name}"|
Custom Name,"?{Name|No Name}"} ?{Show Name?|No,--off showplayers_name|Yes,--on showplayers_name}

I think.

That did the trick, thank you!

I am never not surprised at how helpful and brilliant you guys are.

Current working script thing here:

!token-mod {{
--set bar1_link|none
--set bar1|?{Enter HP Value|
Roll HP,[[@{selected|npc_hpformula}]]|
Custom HP,?{Custom HP Value}|}
--set bar2_link|ac
--set bar3_link|npc_speed
--off showplayers_bar1
--off showplayers_bar2
--off showplayers_aura1
--off showplayers_aura2
--set name|?{Choose a Name|
Use Sheet Name,"@{selected|character_name}"|
Custom Name,"?{Name|No Name}"} ?{Show Name?|No,--off showplayers_name|Yes,--on showplayers_name}
}}