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

Get Selected Token's Character

1612794449
kahn265
Pro
API Scripter
Hi all! I'm currently working on a script for Starfinder (Simple) Sheets that reads a stat block posted in GM Notes and updates the "NPC" page with the values. In Progress Script link here -&gt;&nbsp; <a href="https://gist.github.com/russellasinclair/c8406405b077fc68bb735f8957a88fc9" rel="nofollow">https://gist.github.com/russellasinclair/c8406405b077fc68bb735f8957a88fc9</a> I've been combing through the docs and can't figure out how to do the following: Click on a token that represents the character I want to populate Run the command that updates the character I know it's got to be pretty simple, but I just can't suss it out.&nbsp; Thanks in Advanced
1612797859
kahn265
Pro
API Scripter
Found it.... msg.selected..... *sigh*
1612803450
The Aaron
Roll20 Production Team
API Scripter
Just to be sure, you get the token_id from the msg.selected. You can use that to get the tokens, then get the character_id from each token in the represents property.
1612805641
kahn265
Pro
API Scripter
The Aaron said: Just to be sure, you get the token_id from the msg.selected. You can use that to get the tokens, then get the character_id from each token in the represents property. Yep, Thank you sir!&nbsp; var token = findObjs(msg.selected[0])[0]; var ident = token.get("represents"); var char = findObjs({_id : ident, _type: "character"})[0]; This is much more interesting than the software testing I'm supposed to be doing today.&nbsp; Next fun hurdle is figuring out how weapons &amp; spells are stored. Shouldn't be too hard.&nbsp; And yes, version 0.1 of this only picks the FIRST item if you select multiple. It also needs more error handling. But this is to support my game first. :)
1612811406
The Aaron
Roll20 Production Team
API Scripter
Woot!&nbsp; Definitely come back if you have more questions!
1612911513

Edited 1612911560
kahn265
Pro
API Scripter
Thank Aaron. I've made a great deal of progress since I started this - and I figured I'd point out that I've borrowed your&nbsp; generateRowID / generateUUID &nbsp;code :) <a href="https://gist.github.com/russellasinclair/c8406405b077fc68bb735f8957a88fc9" rel="nofollow">https://gist.github.com/russellasinclair/c8406405b077fc68bb735f8957a88fc9</a> Next step is to get the Spells/Spell-Like abilities working and also putting it in a real repo instead of just a GIST. Also need to throw more stat-blocks at it for debugging.