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

Spawn clock token, prompt for name, copy name to tooltip

1726679062

Edited 1726679216
CryptoCartographer
Pro
Marketplace Creator
Here's what I hope to accomplish: ( ✅ steps are presently working) ✅ Select a target token for SpawnDefaultToken ✅ Click on a token action ✅ This brings up a chat menu of options for clocks: number of segments and colors ✅ SpawnDefaultToken places the selected token on the map but the original token is still selected ❌ Now, I need to manually select the new token and click on its token action, which ✅ Prompts for a name ✅ Puts that name into the Nameplate and the Tooltip of the new token using TokenMod. I would like to remove that manual step, but I cannot figure out how to select either: The product of the Spawn call The most-recently-placed token on the map The clocks are saved as character sheets, and multiple instances of the same clock character token may be present on the map, so I can't use the character name as a unique id. Any ideas?
1726680449

Edited 1726687400
timmaugh
Pro
API Scripter
You can use the tokenName argument of Spawn to give it a unique name, then use the MetascriptToolbox to select the token by that name. Then you don't have to click on anything or even instigate a second command... you can just use that in your TokenMod command line. For it all to work, I'd put it in a batch... something like: !{{   !Spawn ({)     --name|Clock     --tokenName|ClockTemporaryName   (})   (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} }} That Spawn command is obviously probably simplified from what you'd want, but it's just an example. Note that you can't have double braces within the double braces of the batch, so I used the batch versions... ({) and (}) Also notice that I am using the {&delay} tag to allow Spawn to have time to complete. I'm using the {&select} tag to select the token of the name that we are spawning, and I'm deferring both the {&delay} and {&select} tags with a caret to make sure that they don't resolve during the processing of the batch message (the parent message). They should only resolve when the TokenMod command is dispatched. If you have any trouble getting this to work, or if you have questions, post back with your command line and I'll see if we can't get you sorted.
1726680947
CryptoCartographer
Pro
Marketplace Creator
Thanks for the quick response! I will try this out with my existing code and see if it works.
1726686118
CryptoCartographer
Pro
Marketplace Creator
It's not working as expected. I tried troubleshooting by putting the individual commands into chat. This works to create the selected token with the temp name (I had missed that option in the documentation): !Spawn {{--name|04-Red --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood}} But this isn't having any effect on the new token named " ClockTemporaryName " (although it does work if I manually select the new clock token first) !token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} Thanks for any help you can offer.
1726687647
timmaugh
Pro
API Scripter
So, this command: !token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} ...isn't going to work on its own. The metascript constructions are interrupted by the caret character. That's what launching the TokenMod command from within the batch command would do... remove the caret *just prior* to sending the command to TokenMod. That would mean that the {&select} tag would ONLY fire for the TokenMod command (rather than the parent/batch message), and the {&delay} tag would apply to the TokenMod command (again, rather than the parent message). I see what my mistake was (and have corrected it, above): I forgot to include the exclamation points for the embedded commands in the batch... both the Spawn line and the TokenMod line would need an exclamation point. Given that, and given your example command lines, a batched up version of your commands would look more like: !{{   !Spawn --name|04-Red --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood   (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} }} I removed the double braces from the Spawn line... if you're willing to have the arguments all on one line, anyway, you don't need them. Let me know how that works!
1726691209

Edited 1726691256
CryptoCartographer
Pro
Marketplace Creator
Thanks again for the help! We've moved a bit out of my depth with this syntax and the required closing brackets. I rebuilt my chat menu using the code you provided, and what I'm getting is just a prompt for the new name—no token is spawned, and the raw script is spilling into the chat output, so I have missed capturing something. Here's what I've tried (line breaks inserted for clarity) &{template:default} {{name=Place Clock }} {{Segment Count and Color}} ** 4**  [🔴]!{{!Spawn --name|04-Red --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  [🟢]!{{!Spawn --name|04-Green --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-slime (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  [🔵]!{{!Spawn --name|04-Blue --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-water (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  	** 6**  []!{{!Spawn --name|06-Red --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  []!{{!Spawn --name|06-Green --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-slime (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  []!{{!Spawn --name|06-Blue --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-water (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  	** 8**  []!{{!Spawn --name|08-Red --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  []!{{!Spawn --name|08-Green --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-slime (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  []!{{!Spawn --name|08-Blue --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-water (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  **10**  []!{{!Spawn --name|10-Red --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}   []!{{!Spawn --name|10-Green --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-slime (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  []!{{!Spawn --name|04-Blue --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-water (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  	**12**  []!{{!Spawn --name|04-Red --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  []!{{!Spawn --name|04-Green --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-slime (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}}  []!{{!Spawn --name|04-Blue --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-water (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName}}} 
1726751346
timmaugh
Pro
API Scripter
OK... so it looks like you're trying to do a chat menu. There are a couple of things that are going to make that tricky, but nothing that should stop us, I don't think. So, about buttons in general... a couple of things... First, to have a button execute a script, you have to include the HTML replacement for a line break: 
 ...after the initial bang. So the basic syntax would look like: [Label](!
!script-command --args) But yours is a little more complex because you're doing a batch. The batch still requires different commands to be broken across lines -- which is fine, because breaking lines still works inside a button -- and if you don't like that we can do it with "new-line" metascript tags. An example of one of your buttons including line breaks would look like: [Label](!
!{{   !Spawn --name|04-Red --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood   (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} }}) And here is the same button without line breaks, using the metascript "new-line" tag: [Label](!
!{{!Spawn --name|04-Red --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood {&nl} (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} }}) Here are a couple of things to bear in mind as you replicate that across the rest of your buttons: 1) I used the label "Label" just because it looks like you used an emoji that didn't survive being pasted into the forums, so you can put your emoji back in without fear of breaking this syntax 2) The syntax for including a space in a Token-Mod command is to enclose it in quotation marks... however a quotation mark will prematurely terminate your button syntax and the command won't work. For this reason, you can see I replaced every " with " 3) Since we don't want the query to fire when we send the parent message (the chat menu) -- we want it to fire when you click a button for an individual command -- I replaced the question mark character with the HTML variation ? 4) Within a batch command, the syntax for deferring the resolution of a construction until an individual outbound command is dispatched (for instance, waiting until the specific command for TokenMod is sent) is to declare a character (or characters) you will use to "hide" the construction. Since something like: {&delay .2} ...would be detected straightaway if it weren't deferred, it would be applied to the parent message (the batch). That isn't where we want it. We want to *specifically* delay the TokenMod command so that Spawn has time to add the token to the game board. Therefore, we have to "hide" it by adding text. The caret will work: {^&delay .2} ...and the way we instruct the batch to remove that character is to declare it within parentheses at the beginning of the TokenMod line: (^)!token-mod ...{^&delay .2} Everywhere that character is found, it will be removed prior to sending the TokenMod message. That means when the TokenMod message is received, the DELAY tag will be recognized. Hopefully that all made sense, but even if it didn't, this is the part that matters: the closing parentheses is *also* a character that will prematurely end your button syntax, so you have to perform an HTML replacement there, too... using ) That should get your buttons working. If you notice that you're getting Spawn to work but not TokenMod, it might be that you have to up that time in the DELAY tag (currently we're allowing .2 seconds... you could up that to .3 or .4 and probably still not notice the wait). If you have trouble converting the rest of your buttons given this information, let me know... but this should get you working!
1726754939
timmaugh
Pro
API Scripter
BTW, Aaron has reminded me that TokenMod will also accept single quotation marks, and those should survive in a button, so you could replace the " HTML replacements with just a single quote, everywhere you see them.
1726761371
CryptoCartographer
Pro
Marketplace Creator
Batching within macros is something I'm not familiar with, so some of this syntax is new to me. Do you happen to know of a forum page which describes it with some detail? My searches have yielded a lot of unrelated threads. Here's an abbreviated chat menu I constructed: &{template:default} {{name=Place Clock }} {{Segment Count and Color}} ** 4** [Red Dot](!
!{{ !Spawn --name|04-Red   --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood {&nl} (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} }}) [Green Dot](!
!{{ !Spawn --name|04-Green --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-slime {&nl} (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} }}) [Blue Dot](!
!{{!Spawn --name|04-Blue  --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-water {&nl} (^)!token-mod --set name|"?{New name}" tooltip|"?{New name}" --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} }}) The chat menu is appearing, letting me make a selection, and then prompting for a new name. But the token is not Spawned. The code seems to be breaking here: "--layer|objects --fx|glow-blood {&nl}" because I'm getting a message that I have suppliedan invalid fx color. Perhaps !Spawn is not liking the {&nl} which follows "  --fx|glow-blood ." I really appreciate your kind assistance with this. I could always fall back to the multi-step process I had working, but I confess that I am irked by the slight inelegance of it.
1726801846
timmaugh
Pro
API Scripter
I get the idea of being bothered by something's "inelegance." Those sorts of things bother me, too. The batching isn't part of standard Roll20 syntax. It's part of what  ZeroFrame  (one of the metascripts) lets you do. The actual post announcing the addition of this functionality is  here . As far as what you have going, it seems you want to use the single-line version. For that version, we're making use of the  new-line tag  to have ZeroFrame insert a line break into the batched commands before... er... ZeroFrame picks it up. (The line break insertion happens during metascript processing, and the batch operation happens during standard script processing.) I had you HTML-escape that tag, turning this: {&nl} into this {&nl} ...because I didn't want the new line character to be added too early (during the batch/parent message). However, now that I look at it more closely, your *true* parent message is the chat menu, and that message isn't even a bangsy message (intended for scripts). It's a flat message. That means that ZeroFrame won't process it at all, and you should be good do use un-escaped versions of the new line tag. I just tested this simple version of what we're trying to do in my game, and it works: [Test](!
!{{This is the first line{&nl}(^)This is the second line {^& delay 4} }}) Running that you'll get a button. Click the button, and you should get the first message to hit the chat, then 4 seconds later, the second line. So... with that said, this should be the new template for those buttons... either without line breaks (using the new line character): [Red Dot](!
!{{ !Spawn --name|04-Red   --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood {&nl}  (^)!token-mod --set name|'?{New name}' tooltip|'?{New name}' --on show_tooltip showname  {^&delay .2} {^&select ClockTemporaryName}  }}) ...or using actual line breaks: [Red Dot](!
!{{   !Spawn --name|04-Red   --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood   (^)!token-mod --set name|'?{New name}' tooltip|'?{New name}' --on show_tooltip showname  {^&delay .2} {^&select ClockTemporaryName}  }}) Let me know if you can't get either of those to work. They work in my test game.
1726858604
CryptoCartographer
Pro
Marketplace Creator
Well, this works as expected: [Test](!
!{{This is the first line{&nl}(^)This is the second line {^& delay 4} }}) But with the chat menu, no joy. I'm able to enter the name at the prompt, but no token is placed. &{template:default} {{name=Place Clock}} {{Segment Count and Color}} ** 4**  [🔴](!
!{{!Spawn --name|04-Red   --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-blood {&nl} (^)!token-mod --set name|'?{New name}' tooltip|'?{New name}' --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} }}) [🟢](!
!{{!Spawn --name|04-Green --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-slime {&nl} (^)!token-mod --set name|'?{New name}' tooltip|'?{New name}' --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} }}) [🔵](!
!{{!Spawn --name|04-Blue  --tokenName|ClockTemporaryName --offset|1,0 --size|1,1 --order|front --layer|objects --fx|glow-water {&nl} (^)!token-mod --set name|'?{New name}' tooltip|'?{New name}' --on show_tooltip showname {^&delay .2} {^&select ClockTemporaryName} }}) Perhaps I've got a script conflict? I'm currently running TokenMod and SpawnDefaultToken plus the scripts installed by MetaScriptToolbox: APILogic checkLightLevel Fetch libInline libTable libTokenMarkers MathOps MatrixMath Messenger MetaScriptToolbox Muler Path Math Plugger SelectManager SpawnDefaultToken TokenMod Vector Math ZeroFrame Perhaps I am running something I shouldn't be, or not running a script I need?
1726886743
timmaugh
Pro
API Scripter
Well, your command works in my game. Just to double check, you have characters for each of the "04-Red", "04-Blue", etc.? If you can't get it sorted, you can invite me to your game and promote me to GM and I can try to see what's wrong.
1727098188
CryptoCartographer
Pro
Marketplace Creator
I sent an invitation by DM.
1727100303
CryptoCartographer
Pro
Marketplace Creator
…and promoted you
1727230512
timmaugh
Pro
API Scripter
For those who might find this thread later: it was a SelectManager configuraion issue. Once I configured SM with this line: !smconfig +who +playerid Everything worked fine.
1727293342
CryptoCartographer
Pro
Marketplace Creator
Thank you!