r/Roll20 • • 2d ago

Mod Script / API Help (Pro/Elite only) Sheet code help - Keep Higher of two numbers, and Checkbox roll adjustment

I have a game system with two things I'm trying to figure out how to add to the html.

First, there's a stat called Snark, which is equal to one of two potential stats - a character's Wit or their Charm. Snark is the higher of the two, multiplied by 5. So far I have:

name="attr_snark" value="[[ @{charm}*5, @{wit}*5}d1"

But I don't think that's right, and it doesn't seem to be working in the sheet html.

Second, I have a system where an Ability roll can be Boosted. If it's not Boosted, it rolls 1d6 + 1t[Item-Table] + 1d6, with the Item Table giving a specific result from the Item Table. If it is Boosted, it returns 1d6 + 1t[Boost-Table] + 1d6, giving a specific result from the Boost Table.

This is what I have for the Speed ability:

/roll ?{Basic/Boosted|Basic,1d6 + 1t[Item-Dice] + 1d6 + @{Speed}|Boosted,1d6 + 1t[Boost-Dice] + 1d6 + @{Speed}}

This asks every time if the stat is Boosted or not, but I want to streamline this, so that on the sheet there is a checkbox, and if the box is checked, it rolls from the Boost table.

I found a script so that the html can "recognise" that the Speed Boost checkbox is checked, but I'm not sure if I'm doing it correctly - as is, when the box is unchecked, it's returning a 0 value, and when its checked, its returning a 1 value...

<script type="text/worker">

on('change:speedboost_checkbox sheet:opened', (eventInfo) => {

getAttrs(\['speedboost_checkbox'\], (v) => {

const output = {1t\[Item-Dice\]};

const speedboostState = parseInt(v.speedboost_checkbox) || 0;

output.boosted = speedboostState ? '1t\[Boost-Dice\]' : '1t\[Item-Dice\]';

setAttrs(output, {silent: true});

});

});

</script>

If it helps, I have two macros called Basic-Check (/roll 1d6 + 1t[Item-Dice] + 1d6) and Ability-Boost (/roll 1d6 + 1t[Boost-Dice] + 1d6), so I can easily just get the sheet to roll from the Macros and add the corresponding ability (Like Strength or Speed), but I just need to know what I'm doing wrong to get it to recognise the Boosted/Unboosted state...

Can anyone help with these two things? I'm still scratching the surface with Roll20 and html coding, so any help would be appreciated!

2 Upvotes

3 comments sorted by

•

u/AutoModerator 2d ago

Thanks for posting a Mod Script / API Help question.

Roll20 Mods (API Scripts) Forum is the best place to ask for help with scripts.

To help others troubleshoot, please include: * Whether you installed the script from the One-Click Library or manually imported the code * The name and version of the script, or direct link to the code or Roll20 Forum post * The command or setup that causes the issue * Any sandbox error message from the Mod Scripts page

If your question is answered/issue resolved, it would be nice if you edit the main post to include 'Answered/Issue Fixed'.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/Gauss_Death Pro 2d ago

Hi CRTScream,

Your best bet for Character Sheet coding questions would be the Roll20 Forums or the r/Roll20 Discord server.
Both have Character Sheet coding sections.

Forum: https://app.roll20.net/forum/category/277980
Discord server: https://discord.gg/GH5tM2xUA3

1

u/CRTScream 2d ago

Thank you!