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

Calling TokenMod using character sheet button

Hi everyone! So I've been wracking my brain to figure out if this is possible or not. I'm very new to character sheet development, so what I'm doing may not even be possible and I don't even realize it. Though, it seems like what I'm trying to do should be very simple. I'm working on a custom character sheet that has a series of checkboxes to represent the different status effects that a character can have (almost identical to PF2e sheet). What I would like to accomplish is that if the button is pressed, to set the status effect icon on the character. So, using the PF2E sheet as an example, if I were to select the "Blinded" condition, I would want it to put the "bleeding-eye" symbol on the character on the field. Then, if I were to click the "Blinded" condition again to remove it, it removes the status icon. Would this be possible? Any help would be greatly appreciated!
1723394392
The Aaron
Roll20 Production Team
API Scripter
Yes, but... 1) for PCs, where all tokens that represent the character represent the same character, you can target all the tokens for the PC by supplying --ids @{CHARACTER_NAME|character_id} 2) for mooks/monsters, where each token representing the character represents a separate instance of the character (like goblins), the best you can do is either assume the token is selected (use --ids @{selected|token_id} ) or prompt to choose the affected token (use --ids @{target|which token for poison effect|token_id} )
1723418336

Edited 1723418404
The Aaron said: Yes, but... 1) for PCs, where all tokens that represent the character represent the same character, you can target all the tokens for the PC by supplying --ids @{CHARACTER_NAME|character_id} 2) for mooks/monsters, where each token representing the character represents a separate instance of the character (like goblins), the best you can do is either assume the token is selected (use --ids @{selected|token_id} ) or prompt to choose the affected token (use --ids @{target|which token for poison effect|token_id} ) I think thats fine, luckily! I really only need it for my PCs. For the type of game this is for, I usually also create multiple copies of the same character by copying their sheets instead of using the same one (very annoying, but necessary). So I think it should work out well! The problem that I've been running into is that i keep running into posts where people are stating that you can't declare macros, APIs and the like within sheetworkers or functions, only on buttons. But I don't see how i would accomplish this without doing that. But maybe my information is wrong. Here's an example of something I've tried, if it helps.  Here is my burn button. < input type = 'checkbox' id = 'burned-checkbox' value = '1' name = 'attr_st_burn' title = "Defense -2 CS. 1 Tick per Standard Action/Skipped" /> And here is my script for updating stats, etc.   on ( "change:st_burn" , function () {     getAttrs ([ 'st_burn' , 'DEF_Stage' , 'character_id' ], function ( values ) {         let burnStatus = parseInt (values. st_burn , 10 ) || 0 ;         let defStage = parseFloat (values. DEF_Stage , 10 ) || 1 ;         let characterId = values. character_id ; //         const stageMultipliers = [             0.4 , 0.5 , 0.6 , 0.7 , 0.8 , 0.9 , 1.0 , 1.2 , 1.4 , 1.6 , 1.8 , 2.0 , 2.2         ]; //used for determining stat changes. etc.         if ( burnStatus === 1 ) {             let index = stageMultipliers. indexOf ( defStage );             if ( index <= 1 ) {                 defStage = stageMultipliers [ 0 ];             } else if ( index > 1 ) {                 defStage = stageMultipliers [ index - 2 ];             }             // Call TokenMod to set a red status marker             sendChat ( `/w gm !token-mod --set statusmarkers|red --ids ${ characterId } ` );         } else if ( burnStatus === 0 ) {             let index = stageMultipliers. indexOf ( defStage );             if ( index < stageMultipliers. length - 2 ) {                 defStage = stageMultipliers [ index + 2 ];             }             // Call TokenMod to remove the red status marker             sendChat ( `/w gm !token-mod --set statusmarkers|-red --ids ${ characterId } ` );         }         setAttrs ({             DEF_Stage: defStage         });     }); }); Not entirely sure where i'm missing the mark.
1723431416

Edited 1723431439
vÍnce
Pro
Sheet Author
Is the sendChat() function available from within sheetworkers?  I can't recall ever noticing its use within a sheet.
1723432545
The Aaron
Roll20 Production Team
API Scripter
This is where I have to let the people that know more about character sheets take over. I know there are ways of issuing chat commands from Sheets, but I'll need a sheets expert to talk about it. Let me see if I can find one...
1723433520
GiGs
Pro
Sheet Author
API Scripter
vÍnce said: Is the sendChat() function available from within sheetworkers?  I can't recall ever noticing its use within a sheet. The sendChat function isn't available. You can send to chat through Custom Roll Parsing (or a roll button), but it's not the same as the sendChat function.
1723435275
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
yes, sendChat isn't available in character sheets. the best you're going to be able to do is an api call, although if you are planning on publishing the sheet I would not recommend hard coding an api usage into the sheet.
Scott C. said: yes, sendChat isn't available in character sheets. the best you're going to be able to do is an api call, although if you are planning on publishing the sheet I would not recommend hard coding an api usage into the sheet. Yeah absolutely!  This is strictly for personal use. And ah, yeah, this is what i heard. So how would I go about doing this via an API call? I think I'm familiar with how to do it through a button (putting the macro in the value section of the button).  Unfortunately, this is the first time i'm really exploring the use of API in my games, as I've never found them immediately necessary until now.