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

May 07 (5 years ago)
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 - https://youtu.be/qqCk0sKYhr4

@Nick, I'm missing something. The characterList is empty. I get "Which character?" but no chat menu buttons.

May 08 (5 years ago)
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.

            sendChat("PingMeAPI","/w \"" + playerName + "\" Which character?<br/>"+pingList);
                                      ^                   ^
May 09 (5 years ago)
Gold
Forum Champion

thanks for the video series nick, following on youtube (i'm colbruce on youtube)

May 09 (5 years ago)

Edited May 09 (5 years ago)
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.

            sendChat("PingMeAPI","/w \"" + playerName + "\" Which character?<br/>"+pingList);
                                      ^                   ^

In Javascript, you can use different quote types to nest quotes within a string, like

sendChat("PingMeAPI",'/w "' + playerName + '" Which character?<br/>'+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 "${playerName}" Which character?<br/>`+pingList);

The latter seems clunky at first, but the more you use, the more you appreciate how powerful and flexible it is.





May 09 (5 years ago)
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!

May 09 (5 years ago)
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.

May 10 (5 years ago)
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!