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

Video Tutorial - Creating a Script so Players Can Ping Themselves on a Map

1588895153
Nick O.
Forum Champion
If you've ever wished your players could click a button to send a ping and center their view on their character's token, this video will show you how -&nbsp;<a href="https://youtu.be/qqCk0sKYhr4" rel="nofollow">https://youtu.be/qqCk0sKYhr4</a>
@Nick, I'm missing something. The characterList is empty. I get "Which character?" but no chat menu buttons.
1588940672
Nick O.
Forum Champion
Does the user you're logged in as have characters assigned to them? (As the GM, if I run the command, I don't get the chat buttons either) If you do have characters assigned to you, are there any errors in the console?
I got it to work. I created a new game with just a few tokens. My other game must have some inconsistencies. I did notice, however, that if the playerName has a space, it should be quoted. I added backslash quotes (\") before and after playerName. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sendChat( "PingMeAPI" , "/w&nbsp;\"" &nbsp;+&nbsp;playerName&nbsp;+&nbsp; "\"&nbsp;Which&nbsp;character?&lt;br/&gt;" +pingList); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^
1589011065
Gold
Forum Champion
thanks for the video series nick, following on youtube (i'm colbruce on youtube)
1589012878

Edited 1589062694
GiGs
Pro
Sheet Author
API Scripter
Crimson Prime said: I got it to work. I created a new game with just a few tokens. My other game must have some inconsistencies. I did notice, however, that if the playerName has a space, it should be quoted. I added backslash quotes (\") before and after playerName. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sendChat( "PingMeAPI" , "/w&nbsp;\"" &nbsp;+&nbsp;playerName&nbsp;+&nbsp; "\"&nbsp;Which&nbsp;character?&lt;br/&gt;" +pingList); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^ In Javascript, you can use different quote types to nest quotes within a string, like sendChat( "PingMeAPI" , '/w&nbsp;"' &nbsp;+&nbsp;playerName&nbsp;+&nbsp;' "&nbsp;Which&nbsp;character?&lt;br/&gt;' +pingList); You can also use string literal (aka template literal) syntax which uses the weird backticks (`), and then nest code within ${}, like so sendChat( "PingMeAPI" ,` /w&nbsp;"${ playerName}" &nbsp;Which&nbsp;character?&lt;br/&gt;` +pingList); The latter seems clunky at first, but the more you use, the more you appreciate how powerful and flexible it is.
1589036586
Nick O.
Forum Champion
@Crimson - thanks for pointing that out, I'll update the code to account for the spaces in the player's name @Gold - glad you like them! @GiGs - I didn't know about string literals before - those are definitely the way to go. Thanks!
1589062751
GiGs
Pro
Sheet Author
API Scripter
You're welcome Nick, but I realise I forgot to include the quotes inside the string literal in that example. Have just edited the post. String literals are so powerful and flexible, the more you use them the more you'll wonder how you got by without them.
1589073060
Nick O.
Forum Champion
I've used something similar when I was coding in Python, but I didn't know what they were called. They definitely make life easier! Thanks again!