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

Reacting to attribute creation

1734807650
Ulti
Pro
Sheet Author
API Scripter
Hi. I'm trying to do something on a given attribute creation (to interact with a sheet), but most of the time, the attribute is empty when I receive it on an ` add:attribute `.  The name is filled, but `attr.get('current')` returns an empty string. Do others also have that issue? My best solution so far is to wait a bit and try again to read the current value of the attribute. Would there be an other event to listen? If not, is that issue looked at for the new API support?
It’ll be helpful to post the actual code you are using, any in game commands, and screenshots of the output. 
1734856445

Edited 1734856461
Ulti
Pro
Sheet Author
API Scripter
Ooh, I thought this was likely common knowledge. The fact that you ask for the code gives me hope that I did something wrong, then. Here is the code excerpt: ...    5 var COFantasy2 = COFantasy2 || function() { 6 "use scrict"; ... 2560 function treatSheetCommand(attr, nb = 0) { 2561 let jcmd = attr.get('current'); 2562 if (jcmd === '' && nb < 2) { 2563 _.delay(function() { 2564 treatSheetCommand(attr, nb + 1); 2565 }, 2000); 2565 return; 2567 } 2568 let cmd; 2569 try { 2570 cmd = JSON.parse(jcmd); 2571 } catch (e) { 2572 error("Error parsing sheet command (" + jcmd + ")", attr); 2573 attr.remove(); 2574 return; 2575 } 2576 if (cmd) { 2577 switch (cmd.action) { 2578 case 'alias': ... 2589 } 2590 attr.remove(); 2591 } 2592 2593 function attributeAdded(attr) { 2594 let n = attr.get('name'); 2595 if (n == 'cofantasy') treatSheetCommand(attr); 2596 } ... 2650 return { ... 2654 attributeAdded, 2655 }; 2656 }(); 2657 2558 on('ready', function() { ... 2664 on('add:attribute', COFantasy2.attributeAdded); ... 2669 }); Without the code from line 2562 to 2567, the variable jcmd is empty most of the time, even though I can see on the sheet that the attribute is filled with the expected value. Sometimes it is ok for a whole session, most of the time is is always empty during a session, and once I saw the behavior change in the middle of a session. I've had similar issues with token names at token creation for years. Maybe I wrote this code to wait until the token name is actually filled for nothing?