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

[Bug[API]] Console log does not accurately/reliably log duplicate items.

1448602642

Edited 1448608571
Chris D.
Pro
Sheet Author
API Scripter
Compendium Curator
I was trying to follow my code execution to make sure it was working correctly, and it was looking as if _each loops were not executing the correct number of times, but I am now convinced they are, but there is a bug with the log() function where it will not correctly log duplicate items. Here is my test case. var tst = [ 1, 2, 3, 4, 5, 6, 7 ,8]; _.each( tst, function ( item) { // log( item); log( "here"); }); The results are "Parse Test" "here" "here" "here" "here" "Fallout" Note: that I only got 4 here lines. Sometimes I will get 3 or 5. However if I swap the commented out log files, I will accurately get it counting from 1 to 8.  so so long as the log file is the same as the previous one, it sometimes seems to skip it, but always gets unique ones correct. 
1448640221
The Aaron
Roll20 Production Team
API Scripter
Verified Logging of duplicate messages results in fewer log events than it should. I used this script to verify.  It tries the logging at 3 different times (before ready occurs, during the ready event, and after ready has finished) just to be certain it doesn't have to do with internals getting set up.  var logSame = true;  log('begin pre-ready loop test'); var tst = [ 1, 2, 3, 4, 5, 6, 7 ,8]; _.each( tst, function ( item) {     if(logSame) {        log( "here");     } else {         log('item: '+item);     } }); log('end pre-ready loop test'); on('ready',function(){     log('begin ready loop test')     _.each( tst, function ( item) {         if(logSame) {            log( "here");         } else {             log('item: '+item);         }     });     log('end ready loop test');          setTimeout(function(){         log('begin post-ready loop test')         _.each( tst, function ( item) {             if(logSame) {                log( "here");             } else {                 log('item: '+item);             }         });         log('end post-ready loop test');     },1); }) With logSame set to false, I get: "begin pre-ready loop test" "item: 1" "item: 2" "item: 3" "item: 4" "item: 5" "item: 6" "item: 7" "item: 8" "end pre-ready loop test" "begin ready loop test" "item: 1" "item: 2" "item: 3" "item: 4" "item: 5" "item: 6" "item: 7" "item: 8" "end ready loop test" "begin post-ready loop test" "item: 1" "item: 2" "item: 3" "item: 4" "item: 5" "item: 6" "item: 7" "item: 8" "end post-ready loop test" With logSame set to true, I get some variation on: "begin pre-ready loop test" "here" "here" "here" "end pre-ready loop test" "begin ready loop test" "here" "here" "here" "here" "end ready loop test" "begin post-ready loop test" "here" "here" "here" "end post-ready loop test" In the interim, you could write your own logging function that prefaces with at number to prevent the problem: var nlog=(function(l){ var reallog=l, cnt=0; return function(arg){ reallog( (_.contains(['string','number'],typeof arg) ? '<'+(++cnt)+'>: '+arg : arg ) ); }; }(log)); You could actually name that log and it would replace the built in log function.