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

sendPing... why it no worky?

November 11 (1 month ago)
GM
Pro

I use a player called "Gloria" on a big screen to show the players a ship viewscreen like in StarTrek.
I want to send a series of pings for the players to see where a radio transmission is coming from. It does not work.
In fact, I cannot seem to make a ping appear via the API at all!

Here's my code: 

*on("ready", () => {
    on("chat:message", (msg) => {
        if (msg.type === "api" && msg.content === "!distress") {
            startPinging();
        }
    });

    const pingInterval = 5000; // Time between pings in milliseconds (5 seconds)
    const duration = 55000; // Total duration in milliseconds (55 seconds)
    const numPings = Math.floor(duration / pingInterval); // Number of pings to send


   const graphicName = "GRID-1";
   const bar3Value = "planet";

   const startPinging = () => {
        const graphic = findObjs({
            _type: "graphic",
            name: graphicName,
            bar3_value: bar3Value
        })[0];


        if (!graphic) {
            log(`No graphic found with name '${graphicName}' and bar3 value '${bar3Value}'`);
            return;
        }

        const pageId = graphic.get("pageid");
        const left = graphic.get("left");
        const top = graphic.get("top");
        for (let i = 0; i < numPings; i++) {
            setTimeout(() => {
                sendPing(left, top, pageId, '-Nj_Dg6a5ikbFyo8uxEM', false);
            }, i * pingInterval);
        }
    };
});

November 12 (1 month ago)
The Aaron
Roll20 Production Team
API Scripter
sendPing() is not working on Jumpgate currently. They are working on a fix for that. 
November 12 (1 month ago)
GM
Pro

I dont use Jumpgate for fear of my many custom scripts, and because it consistently failed to copy my stuff over. Im making the move in 2025 or so.

November 14 (1 month ago)
The Aaron
Roll20 Production Team
API Scripter

Hmm. I started digging into this, and it appears that sendPing() is broken.  I'll get a repro script to the devs.

November 14 (1 month ago)
The Aaron
Roll20 Production Team
API Scripter

Ok, now I'm not so sure.  It seemed to not be working originally, but now I'm getting it to work consistently.  Try this version.  The only real thing I changed is grabbing the creating player's player id and using that for the ping color:

on("ready", () => {

  const getCreator = () => findObjs({type:'player'}).reduce( (m,p) => (m.id < p.id) ? m : p );
  let PingPlayerID = getCreator().id;


  on("chat:message", (msg) => {
    if (msg.type === "api" && msg.content === "!distress") {
      startPinging();
    }
  });

  const pingInterval = 5000; // Time between pings in milliseconds (5 seconds)
  const duration = 55000; // Total duration in milliseconds (55 seconds)
  const numPings = Math.floor(duration / pingInterval); // Number of pings to send


  const graphicName = "GRID-1";
  const bar3Value = "planet";

  const startPinging = () => {
    const graphic = findObjs({
      _type: "graphic",
      name: graphicName,
      bar3_value: bar3Value
    })[0];

    if (!graphic) {
      log(`No graphic found with name '${graphicName}' and bar3 value '${bar3Value}'`);
      return;
    }

    const pageId = graphic.get("pageid");
    const left = graphic.get("left");
    const top = graphic.get("top");
    for (let i = 0; i < numPings; i++) {
      setTimeout(() => {
        sendPing(left, top, pageId, PingPlayerID, false);
      }, i * pingInterval);
    }
  };
});


November 14 (1 month ago)

Edited November 14 (1 month ago)
GM
Pro

HMMM.... It still doesnt work. Perhaps it's because I am the GM and I'm making an NPC the ping target as a token action?
For context, Im using this to make a planet ping out like the radar script would while a distress call track is playing.

The character represented is named 'planet', the token is named 'GRID-1'. I feel like somewhere in there is the issue.

If I can't solve this, I'll just try a setInterval with the !radar script and see how that goes?

Also, THANK YOU. You, Timmaugh and a few others deserve a frosty or caffeinated beverage or 3 on me.


The Aaron said:

Ok, now I'm not so sure.  It seemed to not be working originally, but now I'm getting it to work consistently.  Try this version.  The only real thing I changed is grabbing the creating player's player id and using that for the ping color:

on("ready", () => {

  const getCreator = () => findObjs({type:'player'}).reduce( (m,p) => (m.id < p.id) ? m : p );
  let PingPlayerID = getCreator().id;


  on("chat:message", (msg) => {
    if (msg.type === "api" && msg.content === "!distress") {
      startPinging();
    }
  });

  const pingInterval = 5000; // Time between pings in milliseconds (5 seconds)
  const duration = 55000; // Total duration in milliseconds (55 seconds)
  const numPings = Math.floor(duration / pingInterval); // Number of pings to send


  const graphicName = "GRID-1";
  const bar3Value = "planet";

  const startPinging = () => {
    const graphic = findObjs({
      _type: "graphic",
      name: graphicName,
      bar3_value: bar3Value
    })[0];

    if (!graphic) {
      log(`No graphic found with name '${graphicName}' and bar3 value '${bar3Value}'`);
      return;
    }

    const pageId = graphic.get("pageid");
    const left = graphic.get("left");
    const top = graphic.get("top");
    for (let i = 0; i < numPings; i++) {
      setTimeout(() => {
        sendPing(left, top, pageId, PingPlayerID, false);
      }, i * pingInterval);
    }
  };
});





November 14 (1 month ago)

Edited November 14 (1 month ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

Is the player flag on the page where the script is being run?

November 14 (1 month ago)
GM
Pro


keithcurtis said:

Is the player flag on the page where the script is being run?


Yep. That was my 1st “lemme check” moment prior to posting. 

November 15 (1 month ago)
The Aaron
Roll20 Production Team
API Scripter

When you say you're using an NPC ID, are you taLking about as a parameter to sendPing()?

November 15 (1 month ago)
GM
Pro


The Aaron said:

When you say you're using an NPC ID, are you taLking about as a parameter to sendPing()?


I omitted the playerId and now it works fine. SO weird.
I have a "display character". I use that character's view (the ship's AI) on a bigscreen during in-person play, while the Crew uses their laptops to do their own tasks. Think captain Kirk/Picard saying "on screen".
So, it works now, though it would be cooler if I could decide the color of the ping... but now Im asking too much, sir.
Here's the hacked together quick demo I posted elsewhere last week if you're curious. https://youtu.be/bAP1EkkPKSk?si=fgb1CN3MoFdkTvtl

November 15 (1 month ago)
GM
Pro


November 15 (1 month ago)
David M.
Pro
API Scripter

I'm just here to say bravo to your incredible in-person game setup! Really top-notch immersion. That certainly took a lot of effort to implement, but the results are fantastic!

November 15 (1 month ago)
GM
Pro


David M. said:

I'm just here to say bravo to your incredible in-person game setup! Really top-notch immersion. That certainly took a lot of effort to implement, but the results are fantastic!


You have no idea how much that means to me. Im guessing you watched my demo? That's less than half of what Ive done over the past year of working on this. It's a labor oof love

December 19 (2 weeks ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

FWIW, sendPing on Jumpgate is now fixed.

December 19 (2 weeks ago)
timmaugh
Pro
API Scripter

Going to second what David said. That's impressive game setup, my person!

December 20 (2 weeks ago)
GM
Pro


timmaugh said:

Going to second what David said. That's impressive game setup, my person!


Thanks so much. I owe it all to you guys. Here is a hacky, super incomplete demo. There’s far more. I even turned one screen into a sci-fi clone of panzer general 2. 

7min demo https://youtu.be/bAP1EkkPKSk?si=jGdOfmdiogh4Ol7c

Panzer General Clone

30sec Airstrike https://imgur.com/gallery/rL99lpr

30sec Mechs! https://imgur.com/gallery/ylS8GJP


December 20 (2 weeks ago)
GM
Pro


timmaugh said:

Going to second what David said. That's impressive game setup, my person!


timmaugh said:

Going to second what David said. That's impressive game setup, my person!


Thanks so much. I owe it all to you guys. Here is a hacky, super incomplete demo. There’s far more. I even turned one screen into a sci-fi clone of panzer general 2. 

7min demo https://youtu.be/bAP1EkkPKSk?si=jGdOfmdiogh4Ol7c

Panzer General Clone

30sec Airstrike https://imgur.com/gallery/rL99lpr

30sec Mechs! https://imgur.com/gallery/ylS8GJP