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

Probably an easy one this time... sigh... it feels silly to even ask.

1729436341

Edited 1729436431
GM
Pro
I have dials and indicators in my game. I'd like, when one of them changes currentSide or moves layers, to send a non-pulling but visible ping on the current page. It's just a way to make the party (and me) aware of a change to their Spaceship. I use the bar 3 value of "dial" to keep these tokens easy to grab. I'm not super familiar with using previous but no time like the present. It isn't visibly pinging anything! I've commented my code for easy reading. No doubt, this is a simple and silly fix... on("change:token", function(obj, prev) {     const playerPageId = Campaign().get("playerpageid");     // Initialize array of tokens     let dialTokens = [];     // Only do stuff if the token is on the current player page     if (obj.get("pageid") === playerPageId) {         // Check if the token's bar3_value is "dial"         if (obj.get("bar3_value") === "dial") {             // Check if the layer or current side has changed             if (obj.get("layer") !== prev.layer || obj.get("currentSide") !== prev.currentSide) {                 // Add the token to the array                 dialTokens.push(obj);             }         }     }     // Loop through each token in dialTokens and send an orange ping     dialTokens.forEach(function(token) {         const tokenX = token.get("left");         const tokenY = token.get("top");         // Send an orange ping to the token's location, visible to all but without pulling players         sendPing(tokenX, tokenY, playerPageId, null, true, "orange");     }); });
1729439623
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
HI GM! Just a quick check: is your game on Jumpgate? API-based pinging does not yet work on Jumpgate.
I’ve not switched to jump gate. With 2 dozen custom scripts, I’m scared to just yet. 
1729450966
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Jumpgate will break a few things, but the Beacon sheet breaks a lot (provided you are trying to make any script interact with the sheet.)
1729461639

Edited 1729462337
GM
Pro
I feel ya. I'm generally excited for it... for my next campaign. We're running Stars Without Number Revised Edition sheet, so I've no idea how that all goes. I've actually been trying to work less from character sheets, especially around space combat. But I do like formatting sendChats with templates. It's a nice touch. It's been a fun ride learning javascript and making things on a screen do things on a screen. If you're creative, you can make almost anything happen. 
@keith Curtis. New script does everything correctly (you can see the tests I put in), but it doesnt send the ping, though it says it did. on("ready", function() {     // Function to ping the token's location (visible to all, white ping, does not pull players)     function pingLocation(token) {         const x = token.get("left");         const y = token.get("top");         const pageId = token.get("pageid");         sendPing(x, y, pageId, null, true, "white");     }     // Function to create the list of tokens with 'dial' in bar 3     function updateTokenList() {         const tokensWithDial = findObjs({             _type: "graphic",             bar3_value: "dial"         }).map(token => ({             id: token.id,             layer: token.get("layer"),             side: token.get("currentSide") || 0 // Handle if currentSide is undefined         }));         return tokensWithDial;     }     // Initial setup: list of tokens with 'dial' in bar 3     let tokensWithDial = updateTokenList();     // Listen for token changes     on("change:graphic", function(token) {         tokensWithDial.forEach(token => {             let tok = token.id;             let msg = `the token id is: ${tok}.`;             sendChat("Adding this tokenID",msg);         });         // Check if this token is in our list         const tokenData = tokensWithDial.find(t => t.id === token.id);         let tokid = tokenData.id;         let temptok = `tokenData id is: ${tokid}`;         sendChat("tokenData before if statemtnet is: ",temptok);         if (tokenData) {             // Get the current layer and current side             const currentLayer = token.get("layer") || 0;             const currentSide = token.get("currentSide") || 0;             let msg = `The current layer is: ${currentLayer} and the current side is: ${currentSide}`;             sendChat("tokenDataTest",msg);             // If layer or current side has changed, send a ping and update the token data             if (tokenData.layer !== currentLayer || tokenData.side !== currentSide) {                 pingLocation(token);                 sendChat("PingTest","The ping was triggered.");                 // Update the token's layer and side in the list                 tokenData.layer = currentLayer;                 tokenData.side = currentSide;             }         }         else { sendChat("API","no tokenData const"); }     }); });
1729525285

Edited 1729560866
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
You might be running into an issue with your sendPing function. You are specifying a color, which I don't think is an actual parameter. From the wiki page: left (Number) The x-coordinate to place the ping at. top (Number) The y-coordinate to place the ping at. page_id (String) The id of the page Roll20 object to place the ping on. player_id (String, optional) The ping will use the specified player's color. If player_id is omitted, the ping will be yellow. moveAll (Boolean, optional) If moveAll is true, all of the players on the appropriate page will have their views centered on the ping. If no value is provided for moveAll, it defaults to false; when it is false, no players are moved, but the ping is visible to everyone. visibleTo (String, Array, Variable, optional) Specifies one or more players that will receive the ping. If at least one player is specified, no other players will see the ping or be moved. The color is determined by the player_id parameter. When I wrote Ping Buddy, I needed a transparent ping option and solved it by temporarily changing the GM color to transparent, issuing the ping and then reverting the color. If you don't give a player ID, it's yellow. Your last parameter that you are using to specify color is invalid. It is expecting an array of player IDs.
Well then it really was stupid and silly. Thanks!