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

Specific scripting how-to questions (tokens & custom attributes)...

Using scripting, I can: Create a new attribute on the D&D 5e character sheet, using ChatSetAttr . Display the value on bar 3 of the character's current token using  TokenMod . What I'd LIKE to do is: Set the token's bar3_link to the new custom attribute (and have it be available for the user to select via the drop-down).  I can set it to any REGULAR attribute via TokenMod, but custom attributes seem to fail... Make these changes the token defaults for the character, so that any new tokens created for the character have these settings. Does anyone have suggestions for how to do this via scripting? Thanks in advance...  :)
1678941083
The Aaron
Roll20 Production Team
API Scripter
Can you post the commands you're using?  TokenMod can set the link like this: !token-mod --set bar3_link|SomeAttrName Provided the attribute exists at the time it is executed, and exists on the character the token represents. There may be a race condition with the ChatSetAttr, or if you're depending on the selected token, but using @{target|...}, that will break things. TokenMod Dan set the default token with: !token-mod --set defaulttoken
1678943893

Edited 1678943929
My reproduction steps: Setup:  Grab a Worg out of the compendium into my game, put a token on my blank map. 1) Create the new attribute: !setattr --name Worg --npc_passive_wisdom|42 Result: ChatAttr confirms success.  (Just using 42 to be a huge, conspicuous number for testing.)  :) 2) Display the value on the token: !token-mod {& select Worg} --set bar3_value|@(Worg.npc_passive_wisdom) Result: Token displays value. 3) Set the bar3_link to an NON-CUSTOM attribute: !token-mod {& select Worg} --set bar3_link|npc_pb Result: Edit token, see link in place. 4) Set the bar3_link to my custom attribute:   !token-mod {& select Worg} --set bar3_link|npc_passive_wisdom Result: Edit token, link has been CLEARED. It certainly seems like the attribute is THERE, and AVAILABLE... and STANDARD attributes show up immediately in the link... but my custom one just clears it.  I didn't grab a screen shot, but my custom attribute isn't in the drop-down list either... I'm using SelectManager to pick my character, and this is the only token on the screen for him... and I'm currently executing the commands manually, one at a time, so there should be plenty of time...  Any thoughts?  :)  Thanks for the help...
Are you seeing 'npc_passive_wisdom' in the character's Attributes list after you use the ChatSetAttr command to create it? Try setting the attribute: !setattr --name Worg --npc_passive_wisdom|42 Then run this command:  @{Worg|npc_passive_wisdom} Do you get an output of '42' in the chat? Also, do you have more than one character in your Journal named 'Worg' or that has 'Worg' in the name? The issue may be that the wrong character is being update or called from.
1678984825

Edited 1678989436
Jarren: On Step 2 of my reproduction above, I use this command: !token-mod {& select Worg} --set bar3_value|@(Worg.npc_passive_wisdom) to set the value on the token bar, and it succeeds.  Note the last part of that command.  :) There's only the one character "Worg", and only one token for him on the map... Thanks for the thought, though... :) EDIT: Ummm... OK.... I foolishly assumed the two similar statements would work the same... but your exact command: @{Worg|npc_passive_wisdom} results in: "No attribute was found for @{Worg|npc_passive_wisdom}" So what exactly is happening here? SetAttr is setting SOMETHING that can then be read.  Is it not really an "attribute"? Confused now... :(
1679274823

Edited 1679274861
I've been attempting to investigate further, but it's only increased my confusion. To wit: I deleted the worg character utterly, as well as every icon from every map it was on (it only had one icon on each of two maps). I then brought a fresh worg in from the compendium, put his token on one map, and checked the stat using Fetch, from my ScriptCards script: !scriptcard {{ --+PW:|@(Worg.npc_passive_wisdom) }} It's... still 42.  I couldn't have changed the frikken COMPENDIUM could I?  So I deleted the character (and token) again and LEFT it deleted. SAME RESULT.  42.  The character is DELETED, but the value remains. I exitted the game.  I restarted the API sandbox.  I restarted the game, and reran the above script. SAME RESULT.  42. I suppose I could try another browser entirely, but seriously... what the hell is going on here? If I change "Worg" to some other name, it comes back blank.  As it should.  Worg is the only character where I only created this "attribute". I thought "ChatSetAttr" was setting an attribute on a character sheet.  That was, you know, tied to the character sheet somehow. But Jarren's test from above seems to indicate that I don't have an attribute.  And this new test seems to indicate that I have the Zombie Value From Hell, Destined To Haunt My Game Until The End Of Time. Questions: What is it that ChatSetAttr set?  (See reproduction step 1, above.) How do I get rid of it? What is the recommended way to set an actual, previously-non-existing, numeric character attribute, that would show up in a token bar's drop-down list (and, apparently, display with the following syntax)?   @{Worg|npc_passive_wisdom} (I see that ScriptCards claims to have a built-in way to set character attributes; I'm trying to decide how brave I am after this confusion.) Apologies; Roll20 scripting is very new to me, and the every-conceivable-permutation-of-random-punctuation syntax used by ScriptCards and the various metascript addons, makes the learning curve rather... steep... Any help wrapping my brain around this is greatly appreciated...
This sounds like you have another character named ‘Worg’ or that has ‘Worg’ in the name. Have you checked archived characters as well?  If you’d like to PM me a game invite and promote me to GM I’m happy to take a look. 
1679277786
timmaugh
Pro
API Scripter
I ran some tests of this and I, too, got some odd results. It wasn't dependent on whether the attribute was native to the sheet or one that I created. Here is a screenshot of what I ran and the output. First, I output to chat the command I was *about* to run, then I ran the command. So, in looking at these images, you can read from top down: It didn't seem to matter whether the original attribute was ever set (in the above, it was not initially set to a value), or whether I took the time to give it a value first: I already shared this with Aaron, and I know he's on it. I just didn't want Moosey to think they were on an island and seeing things others weren't.
...goddammit.   You're right, of course. I went through my ENTIRE CAMPAIGN, I knew exactly what characters I had where, I was very thorough... but I'd forgotten that waaaaaay down at the bottom, we'd added a folder of imported "mini-campaigns" meant to just drop in wherever, and it had creatures in it.  Including a worg.  Who'd been eating all of my "add attribute" commands, causing mysterious missing results on MY worg, and so on. *SIGH* All of that is deleted now (I kept the maps and the handouts, but the monsters, I can copy from the compendium myself if/when needed). Thanks again for beating the glaringly obvious into my brain.  I suspect I'm going to start seeing more reasonable/consistent results going forward...
1679378399

Edited 1679378721
Just to give everyone on this thread an update: After another lengthy thread on poor Kurt J's Discord channel where I continued to prove myself a newbie, I finally have a working script that accomplishes my full goal: It loops through ALL NPC tokens on the page that the GM is currently viewing. It reads the SENSES attribute of the character the token belongs to. It parses that attribute until it gets a numeric value for PASSIVE PERCEPTION. It sets a NEWLY CREATED character attribute, NPC_PASSIVE_WISDOM, to that value. It sets the BAR3_LINK of the token to that attribute. It sets the BAR3_VALUE to that value. It sets the newly modified token to be the DEFAULT TOKEN for the character it belongs to. It then proceeds to the next NPC token on the page. It does all of this using native ScriptCards functionality.  (The Default Token bit still uses TokenMod, but Kurt has already added this feature to the upcoming release of ScriptCards, and I will switch to using that feature when it's available without having to use Github.) There's still tidying up to do: I want to add some default functionality, in case I find an NPC token without Passive Perception in their SENSES attribute.  (Does anyone know if *ALL* of the Compendium monsters/NPCs have Passive Perception explicitly spelled out in the SENSES attribute?) I should probably whisper the output to the GM, rather than blasting it to everyone in the game, in case the GM wants to repair a bunch of NPCs in the map quickly. I could probably tidy up the logic and add more comments. But once I'm done, I'll post it in the ScriptCards Examples forum for others to use.  I know that people have been wishing for a passive perception attribute on the D&D5e NPC character sheet... and this automates getting it set up rather nicely...  :) [By the way, this has all been Unbe -- Moosey's husband.  Anytime you see a post about programming, it'll be me.  She GMs, I code under the hood.]  :)
Just a suggestion: I use ‘passive_perception’ for all of my PCs and  NPCs, and it works just fine without creating a new ‘npc_passive_perception’ attribute. The nice bonus is that it’s an automatically scriptworker-created attribute (though it may be blank) so you won’t get any error messages for a missing attribute on characters that don’t have it set up for any reason.  But I like the idea of automatically pulling the value from the ‘senses’ attribute for Passive Perception, which is better than my method of simply including the ‘senses’ attribute in the query for my macro.