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

[Help] Can the "on('chat:message')" be filtered to what it should fire on?

A little more detail.  I'm attempting to write a pseudo-combat script that handles rolls, figures up damage, applies it to the target token, etc..  For some strange reason, even though I only run the macro once it seems as if it is firing twice.  I put in some log statements and this is what I get. "Rolling to Hit" "Calculating to hit roll" "Rolling Damage" "Calculating damage" "Modifying token" ------------------------- "Rolling to Hit" "Calculating to hit roll" "Rolling Damage" "Calculating damage" "Modifying token" What's weird is it shouldn't have gotten past the first "Calculating to hit roll" since the attack actually didn't hit.  My PowerCard says as much and I only get one of those output.  Is it possible the call to PowerCard.process is causing another firing of the script?  Everything driving the logic that outputs those log statements is all behind this check: if (args[0] === '!atk') { So it shouldn't perform anything unless I were to run the macro.  I know it may be tough to diagnose this without the script, but it is pretty rough (right now), and I'm not looking for critique on my coding.  I can certainly share if needed. Thanks!
1448657614
The Aaron
Pro
API Scripter
You're right, that is pretty hard to diagnose. =D Calling another function (like PowerCard.process() ) shouldn't cause a repeat.  You can also check that msg.type === 'API'.
1448657683

Edited 1448658275
Correction: I am getting 2 PowerCards being output...damn strange. Anyway, here's basically the main function along with the event handler and on ready.  I would assume the issue would be somewhere in here since it starts the whole process.  I'm not seeing it and its driving me nuts.    // Chat input processing.    handleInput = function(msg) {         var rollRes = {},             dmgRes = {};         if (msg.type != "api") return;         var playerObj = getObj("player", msg.playerid);         msg.who = msg.who.replace(" (GM)", "");                     var pcMsg = {};         var args = msg.content.split("--");           // Trim leading and trailing spaces from arguments.         var i = 0;         for (i=0; i < args.length; i++) {             args[i] = args[i].trim();         }                 if (args[0] === '!atk') {             var attacker = args[1];             var target = args[2];             var advDisadv = args[3];             var attkType = args[4];             var dmgRoll = args[5];             var dmgType = args[6];             var weapon = args[7];             var special = args[8];             var save = args[9];             var saveDC = args[10];             var effect = args[11];                          // Get attributes from selected and target.               var aAttr = getPCAttr(attacker);             var tAttr = getNPCAttr(target);             // To Hit Roll              rollRes = attackRoll({targetAC: tAttr.AC, advDisadv: advDisadv, profBonus: aAttr.profBonus, attkType: attkType,              strMod: aAttr.strMod, dexMod: aAttr.dexMod, gMHit: aAttr.gMHit, gRHit: aAttr.gRHit});             pcMsg.content = "!power --format|COMBAT --name|API Output --To Hit:|[[" + rollRes.toHitRoll + "]]";             if (parseInt(rollRes.hit, 10) === 1) {                 pcMsg.content += " --Hit Msg:|You hit!";                 // Damage Roll                 dmgRes = damageRoll({targetID: target, targetHP: tAttr.HP, advDisadv: advDisadv, attkType: attkType,                  strMod: aAttr.strMod, dexMod: aAttr.dexMod, crit: rollRes.crit, dmgRoll: dmgRoll, gMDmg: aAttr.gMDmg,                  gRDmg: aAttr.gRDmg, save: save, saveDC: saveDC});                                  pcMsg.content += " --Damage:|[[" + dmgRes + "]]";             }else{                 pcMsg.content += " --Hit Msg:|You missed!";             }             if (parseInt(rollRes.crit, 10) === 1) {                 pcMsg.content += " --Roll Type:|CRITICAL";             }             if (parseInt(rollRes.fail, 10) === 1) {                 pcMsg.content += " --Roll Type:|FUMBLE";             }             pcMsg.content += " --Attack Type:|" + rollRes.attkType +             " --Adv/Disadv:|" + rollRes.advDisadv;              PowerCard.Process(pcMsg, playerObj);             log("-------------------------------");         }       },    registerEventHandlers = function() {       on('chat:message', handleInput);    };    return {       CheckInstall: checkInstall,       RegisterEventHandlers: registerEventHandlers    }; }()); on('ready',function() {     'use strict';     Attack.CheckInstall();     Attack.RegisterEventHandlers(); });
1448660507

Edited 1448660535
*sigh*  It turned out to be a "chair to keyboard" interface issue or a ID10T return code.  :-P  I had inadvertently pasted my script code into another script I had running.  So yeah, two identical scripts processing the same command will produce duplicate output.  Good grief!
+1
1448666668
The Aaron
Pro
API Scripter
Ah!  PEBKAC error! (Problem Exists Between Keyboard And Chair) Man, I can't count the number of times I've done that. :). Glad you got it working!