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

Instancing of hidden attributes

1638919578

Edited 1638920414
Hi there, Problem #1 I want to create three hidden attributes to store some calculations and flags on my character sheet I do not want my players to be able. I have declared the three attributes as follows: < input type = "hidden" name = "attr_initiative" value = "0" /> < input type = "hidden" name = "attr_passe" value = "1" /> < input type = "hidden" name = "attr_locked" value = "0" /> The problem I have encountered is that they do not look to be instanced when the sheet opens. What I need to do to work around is to manually create the above attributes in Attributes and Abilities tab of the character sheet using the same names (minus attr_) and it works. What am I doing wrong and is there a better way to solve this issue? Problem #2 Maybe it is related to the above problem #1 but I also run into problem when I run the following function: function functiontest ( msg ) {     var attribute = 'passe' ;     var characterID = '-Mq5SUNnAl4yvphcKgtu' ;     var character = getObj ( "character" , characterID );     var result = getAttrByName ( character . id , attribute );     sendChat ( 'System' , result ); } The interesting thing is when I change the value of attribute to other non-hidden attributes, it works. Hence my question, when do attributes get created actually and is there a way to make sure they are all instanced correctly and available (aka no need to manually create them).
1638920524

Edited 1638923515
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
This is a misunderstanding of how the character sheet html, the attributes and abilities tab, and firebase all interact. An attribute declared in the html exists for attribute calls. However, it has not been created in firebase until the value changes from it's default. Attributes don't show up on the attributes and abilities tab until they exist in firebase (and repeating attributes never show up on the A&A tab). For macros this means that attributes exist if they are declared in the html regardless of if they show up in the A&A tab. The only time when it matters for getting the value of the attribute is if an API script is searching for the attribute. API scripts that rely on getObj() or findObjs()  will not see attributes that haven't been changed from their defaults because these functions poll the attributes available on firebase. However API scripts can use getAttrByName()  to get the default value of an attribute. Tl;dr : The attributes exist without being in the A&A tab. There is no need to jump through hoops to ensure they exist there. EDIT: Just saw your second question edit. That shouldn't be happening, although testing your code gives me the same behavior (although all three give me the error). Digging in to figure out what's going on. EDIT 2: Ok, not sure what's going on. It is supposed to work the way I outlined above, but that is not happening. I know that this used to work. Also, it isn't just hidden attributes that are being affected by this, it's any attribute at all which has the potential to break a fair number of API scripts. Including my edits to the reproduction sheet and script for completeness: <span>Spaceholder</span> <input type="hidden" name="attr_hidden" value="0"/> <input type="text" hidden name="attr_hidden_text" value="0"/> <input type="text" name="attr_visible" value="0"/> Script: const test = function(){ log('testing function'); var characterName = 'new'; var character = findObjs({type:'character',name:characterName})[0]; let characterID = character.id; let attributes = findObjs({type:'attribute',characterid:characterID}); log(attributes); let hidden = getAttrByName(characterID,'hidden'); let hidden_text = getAttrByName(characterID,'hidden_text'); let visible = getAttrByName(characterID,'visible'); log({hidden,hidden_text,visible}); } on('ready',()=>{ test(); }); on('chat:message',(msg)=>{ if(msg.content === '!poll'){ test(); } }) Output from the logs (regardless of whether done in response to ready or the chat message): "testing function" [] "Error: No attribute or sheet field found for character_id -MqMJHd44RBD8wCh50WP named hidden" "Error: No attribute or sheet field found for character_id -MqMJHd44RBD8wCh50WP named hidden_text" "Error: No attribute or sheet field found for character_id -MqMJHd44RBD8wCh50WP named visible" {}
1638923296

Edited 1638923471
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
In the meantime, there is a workaround to this issue using sheetworkers which will pretty much just automate the manual setting of the attributes. const defaultAttrs = {'hidden':0,'hidden_text':0,'visible':0};//Object describing the default values for attributes on('sheet:opened',()=>{ getAttrs(Object.keys(defaultAttrs),(attributes)=>{ const setObj = {};//where we'll store the default values to be explicitly set Object.entries(attributes).forEach(([name,value])=>{ if(+value === defaultAttrs[name]){//compare the values to see if the value is currently a default value. Note this demo assumes numerical values. Some additional logic would be required to handle both text and numbers setObj[name] = defaultAttrs[name];//set the attribute to its default } }); setAttrs(setObj,{silent:true});//set the attributes. Do it silently because we don't want an extraneous listener to be launched. }) });
1638983699
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
And, whatever bug that was going on seems to have resolved itself. Your script should work now
Thanks Scott but saddly it is not working for me. Something must be wrong in the way I created my character sheet. Is there a limited number of attributes ?