So here's a little illustration of what's going on without looking at all of the code. First of all, here is are my two functions and the sendChat lines I've been using to locate the issue: commandDist = function (msg) {
// partyMembers array of character IDs initialized from state storage
_.each(partyMembers, function (id) {
var member = getObj('character', id);
if (member) {
sendChat('PurseStrings', '/w GM changePurse("' + splits.join(':') + '", "' + id + '", "add")', null, {noarchive:true});
var changed = changePurse(splits.join(':'), id, 'add');
sendChat('PurseStrings', '/w GM We maded it past changePurse()!', null, {noarchive:true});
}
});
},
changePurse = function (pockets, char_id, type='add') {
sendChat('PurseStrings', '/w GM Inside changePurse("' + pockets + '", "' + char_id + '", "' + type + '")', null, {noarchive:true});
// A lot of stuff happens here...
var result = true;
sendChat('PurseStrings', 'changePurse has ended! Result=' + result + ' and char_id = "' + char_id + '"', null, {noarchive:true});
return result;
}, Here is a screenshot taken after one successful call to my script using "!ps --dist 35cp 62sp 388gp" and one unsuccessful call using the same command. The commandDist function uses character IDs stored in state to distribute loot. You'll see all of the above sendChat calls in order as expected, and the expected output in the Loot Distributed box. However, the last one that fails is still sending valid info to the changePurse function but we never get inside that function! You'll also notice that I am successfully calling getObj before we even get to that point. Yes, those sendChat lines are exactly where they are in the code. No extra lines have been removed for space in those places. So, How is it that it can work just fine one moment and break the next? I can repeat my "!ps --dist 35cp 62sp 388gp" call 4-5 times without it breaking. The character represented by "-LEaJelyDOsRnY_dInoW" is simply the first in the list. I have reset the list with another character first and this has not changed the behavior of the script. So, can you see why I am dumbfounded? There is no discernible reason why the code should be breaking. Can there be an issue with the sandbox itself having a hiccup of some sort? I just cannot for the life of me understand how this is happening.