
Long time player, first time posting a question on Roll20.
First let me thank Cazra and The Aaron from whom I adapted much code.
The ultimate goal of the script is to have a character's movement trigger a trap (thanks to Cazra's script "It's A Trap!"), then have the character save vs. the trap if applicable (as yet not included), then have the trap inflict damage / effects to the character (thanks to some modified code from The Aaron's scripts "MonsterHitDice").
An issue arises when a character interacts with a trap (or traps) more than once. On first interaction with a trap, the script works fine:

First trap: Acid Cloud
However, the second and successive times that a character interacts with any trap, this happens:
. 
Second Trap: Rat Trap; Third trap: Acid Cloud again.
Rather than each trap inflicting its own damage, each trigger event inflicts the damage of each trap that has been triggered previously. There appears to be an array that needs to be cleared. I thought "val.length = 0" would do the trick, I was wrong.
Any ideas?
Here is a link to my script (hope I did it right): https://github.com/vorgrist/roll20/tree/master/trap
Suspect code here:
Any help would be appreciated.
Vorgrist
First let me thank Cazra and The Aaron from whom I adapted much code.
The ultimate goal of the script is to have a character's movement trigger a trap (thanks to Cazra's script "It's A Trap!"), then have the character save vs. the trap if applicable (as yet not included), then have the trap inflict damage / effects to the character (thanks to some modified code from The Aaron's scripts "MonsterHitDice").
An issue arises when a character interacts with a trap (or traps) more than once. On first interaction with a trap, the script works fine:
First trap: Acid Cloud
However, the second and successive times that a character interacts with any trap, this happens:
Second Trap: Rat Trap; Third trap: Acid Cloud again.
Rather than each trap inflicting its own damage, each trigger event inflicts the damage of each trap that has been triggered previously. There appears to be an array that needs to be cleared. I thought "val.length = 0" would do the trick, I was wrong.
Any ideas?
Here is a link to my script (hope I did it right): https://github.com/vorgrist/roll20/tree/master/trap
Suspect code here:
if(trap) { var trapName = trap.get("name"); var trapDam = trap.get("bar1_value"); sendChat("msg.who", obj.get("name") + " set off a trap!"); // Inflict Trap damage on("chat:message", function(msg) { if(msg.content.indexOf("trap") !== -1) { sendChat(msg.who,"/r " + trapDam,function(r){ var hp=obj.get("bar1_value") || 0; _.each(r,function(subr){ var val=JSON.parse(subr.content); if(_.has(val,'total')) { hp-=val.total; sendChat("msg.who", trapName + " inflicts " + val.total + " HitPoints of damage!"); val.length = 0 } }); obj.set({ bar1_value: hp }) }); } });
Any help would be appreciated.
Vorgrist