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

Set default token bar attributes

1664245362
Jiboux
Pro
Sheet Author
Compendium Curator
Hello all, Is there any way to set campaign wide that all tokens that represent a character have bar1 to "HP", bar2 to "Karma" ...etc Currently it seems to be set only at token/character level and is rather annoying to do manually each time. I am more specifically looking for the answer after a compendium drop (for a normal token addition to a character we have developped an API button that takes care of it, but since the compendium drop arrives with a token already, I'd like to have it already set with the appropriate bars
1664247683
Gauss
Forum Champion
Jiboux said: Hello all, Is there any way to set campaign wide that all tokens that represent a character have bar1 to "HP", bar2 to "Karma" ...etc Currently it seems to be set only at token/character level and is rather annoying to do manually each time. I am more specifically looking for the answer after a compendium drop (for a normal token addition to a character we have developped an API button that takes care of it, but since the compendium drop arrives with a token already, I'd like to have it already set with the appropriate bars Which game system and character sheet? Some of the game systems/character sheets have controls for that on the Campaign Details page in settings.
1664248088
Jiboux
Pro
Sheet Author
Compendium Curator
Earthdawn 4th edition. I am the character sheet and compendium developper, so I am precisely looking how to implement such defaults :D
1664248722
Gauss
Forum Champion
Ahhh my apologies, I misunderstood your question as being a 'wrong forum' question where a user was trying to find the feature, not a 'how to make the feature'. :) I would investigate other character sheets, some of them can do what you are talking about. Maybe they will point the direction you need to go in.  Otherwise, I cannot help you as I am not a code guy, sorry. 
1664264354

Edited 1664264905
Oosh
Sheet Author
API Scripter
That's pretty much exactly what the appropriately-named default sheet settings are for. An example from the 5e sheet options: { "attribute": "cd_bar1_l", "displayname": "BAR 1 LINK:", "displaytranslationkey": "cd-bar1-link:-u", "type": "text", "description": "On Default Tokens created by doing a Compendium drop onto the virtual table top, link the Bar 1's value to this attribute. If set this will override all other bar settings.", "descriptiontranslationkey": "cd-bar1-link-desc:-u" } You'd just want to add a default key in there, e.g. "default": "hp", I've never added a Compendium myself, so I'm not sure how the corresponding Compendium code looks - the Pathfinder sheet uses the same attribute name for the bar link, so it's possible it's standard across all compendiums. Really unsure about that part though.
1664326725
Jiboux
Pro
Sheet Author
Compendium Curator
Thanks Oosh, I didn't know it could also set token parameters, Disgracefully I must be missing something because using the following JSON in the sandbox (and reloading the default settings), I still don't have any bars on the tokens I drop from the compendium { "html": "Earthdawn.html", "css": "Earthdawn.css", "compendium": "earthdawn", "authors": "Chris Dickey, Jean-Baptiste Faure", "roll20userid": "633707, 5254828", "preview": "Earthdawn.PNG", "legacy": false, "instructions": "The \"Roll20 Earthdawn by FASA\" character sheet is optimized for 4th edition, but currently has limited support for other editions. It works OK all by itself, but works best with the \"Earthdawn by FASA character sheet companion\" API script (The one script enhances both the Earthdawn and 1879 character sheets).\r\rFor more information please see [Earthdawn Sheet wiki page](<a href="https://wiki.roll20.net/Earthdawn_-_FASA_Official_V2" rel="nofollow">https://wiki.roll20.net/Earthdawn_-_FASA_Official_V2</a>).", "useroptions": [ { "attribute": "cd_bar1_l", "displayname": "BAR 1 LINK:", "displaytranslationkey": "cd-bar1-link:-u", "type": "text", "description": "On Default Tokens created by doing a Compendium drop onto the virtual table top, link the Bar 1's value to this attribute. If set this will override all other bar settings.", "descriptiontranslationkey": "cd-bar1-link-desc:-u", "default": "Karma" }, { "attribute": "cd_bar2_l", "displayname": "BAR 2 LINK:", "displaytranslationkey": "cd-bar2-link:-u", "type": "text", "description": "On Default Tokens created by doing a Compendium drop onto the virtual table top, link the Bar 2's value to this attribute. If set this will override all other bar settings.", "descriptiontranslationkey": "cd-bar2-link-desc:-u", "default": "Wounds" }, { "attribute": "cd_bar3_l", "displayname": "BAR 3 LINK:", "displaytranslationkey": "cd-bar3-link:-u", "type": "text", "description": "On Default Tokens created by doing a Compendium drop onto the virtual table top, link the Bar 3's value to this attribute. If set this will override all other bar settings.", "descriptiontranslationkey": "cd-bar3-link-desc:-u", "default": "Damage" }, { "attribute": "API", "displayname": "Is API Installed ?", "description ": "Declares to the character sheet if the API is installed or not.", "type": "select", "options": [ "No API|0", "API|1" ], "default": "0" }, { "attribute": "edition", "displayname": "What Game/Edition is your campaign", "description ": "Declares to the character sheet the edition to be used (Edition 4 is the most widely supported).", "type": "select", "options": [ "Earthdawn 4th Ed|4", "Earthdawn 3rd Ed|3", "Earthdawn 1st Ed|1", "1879|-1" ], "default": "4" }, { "attribute": "show_karma_auto", "displayname": "Header - Show Karma Auto Mode", "description ": "Enables the selection of the Karma Auto Mode, where each individual action can be set to automatically spend Karma or not. Refer to the wiki", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_damage_stun", "displayname": "Header - Show Stun Damage", "description ": "Show or Hide the Stun Damage and other Damage Details", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_wound_treshold", "displayname": "Header - Show Wound Treshold", "description ": "Show a Wound Treshold Box in the header together with a Modifier", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_options_status", "displayname": "Header - Combat Options and Situation Modifiers", "description ": "Toggles the display of the options and statuses in the header, either just the basic ones, or all of them", "type": "select", "options": [ "Basic|0", "All|1" ], "default": "0" }, { "attribute": "show_actnefct_toggle", "displayname": "Left Pane - Action/Effect Toggle", "description ": "Show or Hide the Action/Effect Toggles for the Attributes. These allows to select between rolling an Action or an Effect tets, that have different modifiers applying to them.", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_natural_toggle", "displayname": "Left Pane - Defenses Natural Values Toggle", "description ": "Show or Hide the Natural Defenses Toggle. Natural Defenses are the value of PD, MD, SD, PA, and MA, independantly from any equipment, but taking into account Discipline bonuses", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_overview_miscpool", "displayname": "Overview - Miscellaneous Pools and Movement", "description ": "Show or Hide the Miscellaneous Pools and Movement in the Overview", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_combat_miscpool", "displayname": "Combat - Miscellaneous Pools and Movement", "description ": "Show or Hide the Miscellaneous Pools and Movement in the Combat", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_repeating_mod_exc", "displayname": "Repeating Sections (Talents, Skills ...) - Exceptions", "description ": "In the Talents, Skills and Knacks, shows the advanced parameters for modifier exceptions. These parameters allow fine tuning of the modifiers that applies to a certain test (for example, active defenses are not affected by Defensive Stance -3 on all Action Tests). Note that the sheet has a database of the main Talents and their modifier exceptions, so you need this option only if you want to override the system.", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_repeating_success", "displayname": "API Only - Repeating Sections (Talents, Skills ...) - After roll parameters", "description ": "Show all the parameters that affect the behaviour of the system after rolling. This includes special Effects, Displaying a Text, and Visibility.", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_repeating_links", "displayname": "API Only - Repeating Sections (Talents, Skills ...) - Links", "description ": "Show all the parameters related to links. Refer to Wiki", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_repeating_special", "displayname": "API Only - Repeating Sections (Talents, Skills ...) - Special", "description ": "Shows the Special field, that allows to declare to the system some specific Talents, such as Spellcasting, Initiative, Knockdown or Recovery Replacement. Refer to Wiki", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "uatta", "displayname": "Use All Talents to Advance (PG p453)", "description ": "Specifies if the optional Use All Talents To Advance Option is to be used to recommend Circle Advancement in the Talent Summary.", "type": "select", "options": [ "Core - Disabled|0", "Option - Enabled|1" ], "default": "0" }, { "attribute": "show_container", "displayname": "Equipment - Container Management", "description ": "Enables the Management of the Inventory per container. Refer to Wiki", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_blood", "displayname": "Equipment - Blood Magic", "description ": "Enables the Management of Blood Charms.", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_mounts", "displayname": "Equipment - Mounts", "description ": "Enables the Management of Mounts.", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "show_lifestyle", "displayname": "Equipment - Lifestyle", "description ": "Enables the Management of Lifestyle.", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "0" }, { "attribute": "legend-calc-mode", "displayname": "Legend - Calculated Mode", "description ": "Toggle to display CALCULATED Mode LP Tracking. In the CALCULATED MODE, you only have to record your Career Legend Points @{Career-LP}. Based on all your Rank values and Attribute improvements, the system will fill your Calculated Current Legend Points @{LP-Current-Calc}. Note that the system needs to know the ranks you spent for free at creation. Refer to the info in the CALCULATED MODE for more information.", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "1" }, { "attribute": "LP-SpellsOption", "displayname": "Legend - Standard/House Rule: Spells cost/do not cost LP", "description ": "", "type": "select", "options": [ "Standard - Spells cost LP|1", "Houserule - Spells do not cost LP|0" ], "default": "1" }, { "attribute": "LP-AttribOption", "displayname": "Legend - Standard/Option Rule: Attribute Increases cost/do not cost LP", "description ": "", "type": "select", "options": [ "Standard - Attributes cost LP|1", "Optional - Attributes do not cost LP|0" ], "default": "1" }, { "attribute": "legend-transaction-mode", "displayname": "Legend - Transaction Mode", "description ": "Toggle to display TRANSACTION Mode LP Tracking. In the TRANSACTION MODE, your Career and Current points can be edited. The Current is stored in a separated @{LP-Current} field. You track your LP/SP by Posting transactions in your journal. Transaction can be a Legend Award at the end of an Adventure, or the cost of increasing a Talent Rank. The API will automatically propose you to post some of the transactions. Refer to the tooltip in the TRANSACTION MODE.", "type": "select", "options": [ "Hide|0", "Show|1" ], "default": "1" }, { "attribute": "RollType-Dex", "displayname": "Default Visibility for Rolls - Dex", "description ": "Who should the roll result be shown to ?.", "type": "select", "options": [ "Sheet Default|@{RollType}", "Public| ", "GM|/w gm" ], "default": "@{RollType}" }, { "attribute": "RollType-Str", "displayname": "Default Visibility for Rolls - Str", "description ": "Who should the roll result be shown to ?.", "type": "select", "options": [ "Sheet Default|@{RollType}", "Public| ", "GM|/w gm" ], "default": "@{RollType}" }, { "attribute": "RollType-Tou", "displayname": "Default Visibility for Rolls - Tou", "description ": "Who should the roll result be shown to ?.", "type": "select", "options": [ "Sheet Default|@{RollType}", "Public| ", "GM|/w gm" ], "default": "@{RollType}" }, { "attribute": "RollType-Per", "displayname": "Default Visibility for Rolls - Per", "description ": "Who should the roll result be shown to ?.", "type": "select", "options": [ "Sheet Default|@{RollType}", "Public| ", "GM|/w gm" ], "default": "@{RollType}" }, { "attribute": "RollType-Wil", "displayname": "Default Visibility for Rolls - Wil", "description ": "Who should the roll result be shown to ?.", "type": "select", "options": [ "Sheet Default|@{RollType}", "Public| ", "GM|/w gm" ], "default": "@{RollType}" }, { "attribute": "RollType-Cha", "displayname": "Default Visibility for Rolls - Cha", "description ": "Who should the roll result be shown to ?.", "type": "select", "options": [ "Sheet Default|@{RollType}", "Public| ", "GM|/w gm" ], "default": "@{RollType}" }, { "attribute": "Misc-KarmaRitual", "displayname": "Character - Karma Ritual", "description ": "Select effect on Karma of the NewDay button, between standard 4th ediition rule (refills Karma to Full) and several Homerule options or previous edition rules.", "type": "select", "options": [ "ED4 Core-Fill Pool|-1", "Homerule-Circle|-2", "Homerule-Racial Mod|-3", "ED3-Core-Talent Rank|-4", "None|0", "1|1", "2|2", "3|3", "4|4", "5|5", "6|6", "7|7", "8|8", "9|9", "10|10" ], "default": "-1" }, { "attribute": "StepDisplayFinal", "displayname": "Legend - Step Display", "description ": "Parameter to decide between displaying the Base Value (without modifiers) or Final Value (after all Modifiers) in each of the steps.", "type": "select", "options": [ "Base Values|0", "Final Values|1" ], "default": "1" }, { "attribute": "effectIsAction", "displayname": "General - Effect/Action", "description ": "Very unclear in the rules, but many of the modifiers apply to Action Tests, but it seems that Effect tests are only affected by a few things like wounds. This parameter ignores this rule and considers everything is an action.", "type": "select", "options": [ "Effect is NOT Action|0", "Effect is Action|1" ], "default": "0" } ] }
1664328504

Edited 1664330168
Oosh
Sheet Author
API Scripter
Hrmmm, there might be something that needs to be done on the compendium end - I'm not much help there sorry, since I've never touched any of that! Never mind, it's nothing to do with that - it's just hooked up to a plain old sheetworker in the sheet, the structure is pretty much this: on("sheet:compendium-drop", () =&gt; { const defaultBarSettings = ['cd_bar1_link', 'cd_bar2_link', 'cd_bar3_link']; const tokenBarAttributes = defaultBarSettings.map(setting =&gt; setting.replace(/^cd_/, '')); getAttrs(defaultBarSettings, (values) =&gt; { const tokenOutput = {}; defaultBarSettings.forEach((barSetting, i) =&gt; { if (values[barSetting]) tokenOutput[tokenBarAttributes[i]] = values[barSetting]; }); setDefaultToken(tokenOutput); }); }); The PF and 5e sheets also process 'cd_barX_v' and 'cd_barX_m' for each bar, holding the current and max values. The default for 5e for example, is no bar link, but _v and _m are both set to "hp_max" so that the default behaviour is to drop a mook token - at full HP but not linked to the character sheet HP. I'm assuming the naming convention is to avoid any future issues or confusion of having identically named attributes bar1_link on both the token and character sheet. In the example above I used the proper token attribute name with a cd_ prefix so you can just strip off the prefix and use it as-is. You could do the same with cd_bar1_value and cd_bar1_max if you process them all at once. And.... an extra few keystrokes for a much more descriptive name is a much better idea than the 5e version anyway :) Either way, the name you use in the sheet options JSON obviously needs to match the ones in the sheetworker used by the getAttrs, since all it's doing is grabbing a character attribute. I can't find a definition for setDefaultToken(), so I'm assuming this is an internal function you can call, though I've never used it. edit - fixed bad code
1664508123
Jiboux
Pro
Sheet Author
Compendium Curator
Thanks so much Ooosh, I just saw your reply... I didn't try it yet,but I had no idea that you could interact with the tokens in the sheetworker... This makes me think that I don't even need the JSON, and it could be hardcoded values.
1664586457
Jiboux
Pro
Sheet Author
Compendium Curator
Well, in fact I am not able to make it work... Looking in&nbsp; <a href="https://wiki.roll20.net/Sheet_Worker_Scripts#setDefaultToken.28values.29" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Scripts#setDefaultToken.28values.29</a> I see that bar1_link is not listed in the parameters that can be sent to setDefaultToken... The text clearly describes the use of linking to an attribute, but the example is for hardcoded value... Using Ooosh example, or trying myself to set it, it only works when I have a hardcoded value. var default_attr = {}; default_attr["width"] = 70; default_attr["height"] = 70; default_attr["bar1_value"] = 10; default_attr["bar1_max"] = 15; default_attr["bar2_link"] = "Karma"; setDefaultToken(default_attr);
1664614393

Edited 1664614746
Oosh
Sheet Author
API Scripter
I'd say the documentation on the wiki is wrong - the 5e sheet very clearly sets the 'barX_link' values on the token using this method. I'm not sure what you mean that it only works when you use a hardcoded value - there's no difference between these: default_attr["bar2_link"] = "Karma"; const attributeName = 'Karma'; default_attr["bar2_link"] = attributeName; Are you sure the getAttrs is grabbing the values properly? Have you tried logging them? edit - the 5e sheet is definitely only storing names, not ids:
1664662837
Jiboux
Pro
Sheet Author
Compendium Curator
If it works for the 5e, I really don't understand why it doesn't work for me :(:( To be clear I need something much simpler, where I have "Karma" ,"Wounds" and "Damage" for the 3 bars, so I don't need the default attribute and getAttrs part. When I was speaking about hardcoded values, I meant the example above only writes 70, or 10, or other numbers in the max and values, but doesn't show a link... When I do a testcode like below var default_attr = {}; let crsize = Math.max(1,getInt(data,"CreatureSize")); //Size of the token default_attr["width"] = 70*crsize; default_attr["height"] = 70*crsize; default_attr["bar1_value"] = 10; default_attr["bar1_max"] = 15; default_attr["bar2_link"] = "Damage"; default_attr["bar2_value"] = 5; setDefaultToken(default_attr); If I read back the token object via an API I can find back that bar2_link value is "Damage", but the link is still inactive and doesn't appear when I edit the token through the VTT. If I take a brand new token, and link the bar2 to Damage via the roll20 normal interface, and then I log the token object I find the bar2_link that is an id, and not a name, hence why I believe it needs to be an id ...
1664671926

Edited 1664675291
Oosh
Sheet Author
API Scripter
Yeah there is no common ID for that attribute though - it's randomly generated for each character, so to have a campaign-wide setting it can only really be a name. Maybe try lower case? A quick test in 5e shows me that you end up with the text string in bar1_link when you define an attribute that doesn't exist. So... does damage definitely exist on the sheet? It can't be a default attribute that doesn't exist on the specific sheet, or it won't have a UID to find. So you'd probably want to define a default for it in the HTML with value="10". It might also work with a sheetworker, though the initial drop from compendium to the table might occur before sheet:opened - add:character might work? The attributes should go in a sheet:opened handler to be created properly. You could also try lowercase, thought I'm 99% sure the token drop function does a toLowerCase() anyway when it searches the sheet for the attribute. Uppercase is generally best avoided in attribute names due to the occasional event-related bug.... but it's possible you've found another one. edit - just to be clear on default attributes - on a new character, any attribute that isn't defined in the HTML with a value="x", or in a sheetworker with setAttrs, will grab the character sheet-defined default value. However this is just a value, it's not actually an Attribute Object on the character sheet, so the bar link will fail to find a UID. If it isn't either of those two problems, I might be out of ideas.
1664673928
Jiboux
Pro
Sheet Author
Compendium Curator
OK, it seems (one of) the problem(s) was that I had put the setDefaultToken in a on(change:drop-name instead of a on(sheet:compendium-drop). With this changed I was able to have the links visible when opening the default token properties, but ended up with a different bug... The default token seems "broken", i.e. no token is dropped on the VTT either during the initial compendium drop, or during subsequent journal drops... I have a nice error message in the console:
1664675224
Oosh
Sheet Author
API Scripter
Ah yep, just replied in the other thread. Ignore the bit I said about setting default values in HTML as it was wrong - that doesn't create the attribute on the sheet. It needs to be a setAttrs in a sheet:opened event handler. The example in the other thread was working correctly for me.
1664676197
Jiboux
Pro
Sheet Author
Compendium Curator
Thanks so much... Your idea on the other thread was the right one... Problem was that I didn't set the size of the default token !