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 .
×
D&D 2024 has arrived! Pre-order the new core rulebooks now and get an exclusive pre-order bonus for free!
Create a free account

[Script Request] Get Character.Bio from Selected Token.Represents

I run a narrative heavy game. I use a lot of note-cards and post it notes instead of maps and grids. I also have a bunch of online only players.  This means my note-cards and post-its aren't visible to them like the rest of the players at the table. Yes, I know I can make text boxes and group them together and the like, but I can't stand editing groups of text boxes to store all the notes jotted down during play. I want something more permanent and "file" like. The journals are handy, but can't be nudged around and organized like post-it notes. I like roll20's character sheets and the fact that a token can "represent" a character sheet. I would like a script that fetches a specific character's Bio text via a selected Token's "Represents" value, then places the text next to the token and groups it with the token.  I lack the skill to hack either TokeNotes or DungeonBuddies to do what I need, so I am calling upon the wizards here to aid me.  Any help on this would be appreciated! Workflow: Select a Token or a Group if it is a token, we'll call it $TOKEN Run the script via a simple command-line command, or Ideally: Some sort of context menu on the selected Token if { selected $TOKEN $TOKEN has "Represents" value populated The token represents an actual Character extract the pointer to said Character we'll call this $CHARACTER $CHARACTER has Bio field populated } then { Fetch the $CHARACTER.Bio we'll call this $BIO from now on. Place a text box 80 characters wide we'll call this $BOX Adjacent to $TOKEN perhaps top-right aligned On the same layer as $TOKEN Sized Legibly, (may be preset to say, 14 pt font, or command-line) Color Black (May be preset or command-line) Word Wrap $BIO to 80 characters, placing a non-breaking return at the 80th character Fill $BOX with $BIO Create a group consisting of the $TOKEN and the $BOX we'll call this $GROUP }
1447244019
Lithl
Pro
Sheet Author
API Scripter
Off the cuff, no testing: on('chat:message', function(msg) { if (msg.type !== 'api') return; if (msg.content !== '!displaybio') return; _.each(msg.selected, function(obj) { var token, character; token = getObj('graphic', obj._id); if (token) { character = getObj('character', token.get('represents')); } if (character) { character.get('bio', function(bio) { var text = wordwrap(bio, 80); createObj('text', { pageid: token.get('pageid'), top: token.get('top'), left: token.get('left') + 350, text: text, font_family: 'Arial', layer: token.get('layer') }); }); } }); }); function wordwrap(str, width) { var regex = '.{1,' + width + '})\s|$)|\S+?(\s|$)'; if (!str) return str; return str.match(new RegExp(regex, 'g')).join('\n'); } The biggest problem is that IIRC the top/left value of the text object is the center of the text, and the width and height properties don't actually work, so there's no simple way to figure out where to place it. Also, as far as I'm aware, there's no means in the API to group objects for you.
1447252051
The Aaron
Pro
API Scripter
Probably you'd have to put the text at the top right corner of the token, flowing right, then then watch events moving the token and move the text by the same amount. Also, corrected word wrap: function wordwrap(str, width) { var regex = '(.{1,'+width+'}(\\s|$)|(\\S+?(\\s|$)))'; if (!str) return str; return str.match(new RegExp(regex, 'g')).join('\n'); }
This works well enough, thank you all!