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

ChatSetAttr command as a chat button

1756113701
StéphaneD
Pro
Sheet Author
API Scripter
Hi Using the CRP functions in a sheet worker script, I am trying to have a button in a roll template with a ChatSetAttr command in it The roll template looks like this : &{template:custom} {{title=Equipement}} {{subtitle=Truc}} {{desc=Xanesha}} {{text=Trucmuche est une arme magique affutée +3}} {{Prop:bonus-magique= +3 }} {{Prop:affutee= }} {{Objet=[Equiper](!setattr --sel --fb-from COF2e --fb-header Ajout équipement --repeating_equipement_-CREATE_equip-nom|Truc --repeating_equipement_-CREATE_equip-detail|Trucmuche est une arme magique affutée +3 --repeating_equipement_-CREATE_equip-props|bonus-magique: +3~affutee: ) }} @{Xanesha|token_dsp} I see the button as an hyperlink in the chat, but it does not do anything when I click it.  If I inspect the chat window, I see it as an a element, but there is no href  Same thing if I copy the button part only [Equiper](!setattr ...) and paste it in chat If I change the code in the sheet worker to issue the following command separate from the roll template !setattr --charid @{target|character_id} --fb-from COF2e --fb-header Ajout équipement --repeating_equipement_-CREATE_equip-nom|Truc --repeating_equipement_-CREATE_equip-detail|Trucmuche est une arme magique affutée +3 --repeating_equipement_-CREATE_equip-props|bonus-magique: +3~affutee: I see the popup that asks me to select a token as expected, and when I click the target, it also works as expected Any idea why it does not work as a button in chat ?
1756118377
Ulti
Pro
Sheet Author
API Scripter
The issue seems to be the `:` in the command. Maybe you can try escaping it?
1756121937

Edited 1756121977
StéphaneD
Pro
Sheet Author
API Scripter
Hi Ulti I have tried to escape ':' and even the '~' I had already tried to escape the '|' between the attribute names and values Still no joy, but thx anyway :)
1756134200
vÍnce
Pro
Sheet Author
Have you tried adding "!!!" to the end of your mod macro?&nbsp; <a href="https://wiki.roll20.net/Script:ChatSetAttr#Inline_roll_example" rel="nofollow">https://wiki.roll20.net/Script:ChatSetAttr#Inline_roll_example</a>
1756136041
StéphaneD
Pro
Sheet Author
API Scripter
Hi Vince I don't want to send the setattr command in the roll template with the !!! syntax. I want to display a button using the regular Roll20 button syntax with a label between [...] and the !setattr command inside the (...) [Label](!setattr ...) So that a player who has selected his character's token (thus the --sel in the setattr command) can click this button which should then execute the !setattr&nbsp; API command and add an object to his inventory (in the game system implemented by the character sheet I am developing) You can test it yourself even without the character sheet, using the default roll template &amp;{template:default} {{Objet=[Equiper](!setattr --sel --fb-from COF2e --fb-header Ajout équipement --repeating_equipement_-CREATE_equip-nom|Truc --repeating_equipement_-CREATE_equip-detail|Trucmuche est une arme magique affutée +3 --repeating_equipement_-CREATE_equip-props|magie: +3~affutee: )}} Roll20 creates an hyperlink in the chat window and the label appars with the pink-purplish color, but no setattr command in the href (no href at all actually) and so nothing happens when the link is clicked
1756137915

Edited 1756142454
StéphaneD
Pro
Sheet Author
API Scripter
Nevermind, got it to work As Ulti noticed, the culprit that was preventing the whole thing to work was the ':' in the middle of the command Removing them altogether instead of trying to escape them displays a button as expected (and not an hyperlink) and then the command works as expected Since the inventory item properties (repeating_equipement_equip-props attributes) are a LF-delimited list of 'name: value' pairs, I had already added a sheet-worker to re-format this attribute when it is added via ChatSetAttr as a ~ delimited list. I changed the code to strip the ':' and create 'name value' pairs&nbsp; when outputting the button, and changed the re-formatting code to re-insert the ':' A bit clumsy and convulated, but now it works :)
1756142460
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I just want to point out that you don't need chat set attribute to do this if you are making a custom sheet. This can all be done within sheetworkers via the startRoll function. Additionally, if this sheet is for eventual public release, you'll need to move this functionality sheet side.&nbsp;
1756144044

Edited 1756145416
StéphaneD
Pro
Sheet Author
API Scripter
Hi This sheet is already in the Roll20 repo, this is just optional features — just like those you had with the D&amp;D 5e companion script. Hope the rules are not different between Roll20 sheets and community developed sheets… The idea behind this is to output the name, description and properties of an item from an NPC inventory in the chat along with an « Equip » button, and allow a PC to click the said button to add the item in their own inventory. I don’t see an easy way to do this with the CRP function - I don’t know in advance who will click the button to loot the item. Plus, the properties of items are string data, and this does not fly very well with getting values with the results object in the startRoll callback function. But I’m all ears to any suggestion :) That’s why I use ChatSetAttr.
1756147033
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
ah, if it's additive functionality, it's fine to do with API script. You could still do it via interesting use of startRoll using methods like data passing from Oosh's Adventure's with Startroll . This is the basis of the K-scaffold's send/receive functionality that allows for cross sheet communication and sending json data as base64 encoded data.