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

Including Character Image on roll result

1669980065
Chris Jones
Pro
Sheet Author
As the subject says, is it possible to include the character token image in my roll result? Obviously we're pulling the name attribute down, so i was wondering if i could do the same with the token. I'm using an API script for my rolls, so if i know what the attribute is called, i might be able to work out how to include it. Cheers Chris
1669990745

Edited 1669990797
timmaugh
Pro
API Scripter
Hey, Chris... you could be looking for the "imgsrc" property (attached to the token, this is the token image), or the "avatar" property (attached to the character, this is the character image). Inspector is a script that can help with identifying these sorts of things. It's available in the 1-click. Just run !about to get a help panel, or (in this case) you could select the token and then issue: !about --@{selected|token_id} You'll get an informative panels with buttons that let you flow through to panels of connected information. Alternatively, you could run: !about --put Character name here This would give you the option to look at all tokens and characters that answer that name, so you could see the different between a token and a character.
1669999665
Chris Jones
Pro
Sheet Author
Sorry, what's the "1-Click"? Looking at the page source data doesn't reveal much - it tells me where the image is hosted (an amazon S3 bucket), but it doesn't have a name, or at least not in the same way that when i inspect the "name" attribute, it's listed as "attr_character_name"
Chris Jones said: Sorry, what's the "1-Click"? The '1-click' is the Roll20 script library  of scripts that have been submitted and can be installed in games through the 'Add Script' button instead of manually importing the code.
1670001341
Chris Jones
Pro
Sheet Author
Ah, got it! Unfortunately it's still not showing the attribute name for an image - that i can see at least
1670002395
timmaugh
Pro
API Scripter
There isn't an attribute for the image... the image is a property of the token or the character (depending on what image you're looking for). The only way to get it is to add it in the script (using javascript to pull the imgsrc property from the source token -- or avatar property from the source character), format it in an img tag (html), and include it in your output... or possibly to do it from the command line using a couple of metascripts like Fetch + ZeroFrame. Let me see if I added that ability with the last Fetch release... I know I added it for status markers. If not it should be easy enough to add.
1670005357
timmaugh
Pro
API Scripter
Ok, done. Using Fetch, you can retrieve this property in the chat window. I've added the code to Fetch and submitted a pull request for the changes to be merged into the 1-click, but for now you can get it from my personal repository . (See below for the full list of scripts needed, if you are installing manually). Fetch just got the ability to pull the token image: @(selected.img) ...or the character image: @(selected.char_img) ...or... @(selected.character_img) To use these in a roll template, you could do something like: !&{template:default}{{name=Proof of Concept For @{selected|token_name}}}{{Token Image=@(selected.img)}} {{Character Image=@(selected.char_img)}} {&simple} That looks like this: SCRIPTS REQUIRED: Fetch v2.0.1     dependencies of: Messenger  and  libTokenMarkers ZeroFrame     dependencies of: libInline
1670013373
Chris Jones
Pro
Sheet Author
I think i've got something wrong here, as I keep getting "no attribute found" messages regardless of what combination of text i put into my script. I've downloaded Fetch v2.0.1 js and put that in my API folder, so i'm clearly doing something wrong - it is pretty late for me, and i'm one of these people that understands code enough to be dangerous, but not competent :)
1670014756
timmaugh
Pro
API Scripter
When you say script, I think you're talking about creating a mod in javascript. Is that what you mean, or are you talking about what you put in a macro or ability on the character sheet? Fetch will operate as a chat-level actor... you put some command into the chat box (by typing or clicking a macro), and Fetch will parse it for the things it needs to do (looking for a construction like @(selected.img) ). Fetch is not changing what is available to you in javascript. If you want to get the image from a token in javascript, that would be something like: let token; if (!msg.selected) return; token = getObj('graphic', msg.selected[0]._id); let tokimg = `<img src="${token.get('imgsrc')}">`; You can get the token you're interested in in any number of ways. But once you can get it, you can get the image like this and then you could use that in the output your mod script would eventually send to the chat interface.
1670170527
Chris Jones
Pro
Sheet Author
Sorry, i'm talking about the dice roller macro in my character sheet - at the moment I press the button, and it returns the dice results and the character name. Part of the code in my character sheet HTML refers to @{character_name} as something to call back, so my assumption was i'd need to add in a new criteria here - such as Image=@(selected.char_img)  to my sheet macro, but despite using a few combinations, i'm not getting anything returned. As i said, i know enough to be dangerous :)