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

ChatsetAttr the message in chat says that the attribute has been set but upon checking it has not.

So I have a created attributes on a 3.5 char sheet (I know...everyone groans...) called 00spellSlot01...00spellSlotnn. Using ChatsetAttr, this works: /w gm "@{selected|character_name}" [@{selected|00spellSlot02}](!setattr --sel --00spellSlot02|Used) While this gives the message in chat that you would expect to see upon success (Setting 00spellSlotxx to Used for character abc) but when you check the attribute, it has not been set to the desired value and is, in fact, unchanged: ?{Level| 0,?{Spellslot| 00spellSlot01| 00spellSlot02| 00spellSlot03| 00spellSlot04} | 1,Dork } [CAST](!setattr {{ --sel --?{Spellslot}|Used }} ) So what am I doing wrong?
1598519643

Edited 1598519726
GiGs
Pro
Sheet Author
API Scripter
The problem might be that your attribute names start with numbers. I'm honestly not sure if its valid in roll20 because I've never tried it, but even if it is, it might be causing issues on chatsetattr. commands like the following might just not work properly in chatsetattr: !setattr --sel --00spellSlot02|Used because of the integers at the start of the attribute name.
Ok, but this statement worked: /w gm "@{selected|character_name}" [@{selected|00spellSlot02}](!setattr --sel --00spellSlot02|Used) However, just to check that maybe there might be some inconsistent behavior I changed the attribute name to L0spellSlot00 .. L0spellSlotnn and still had the same results. The ChatsetAttr message says that it set the correct attribute to the new value but that change did not actually happen on the sheet.
Ok, interesting discovery. As I was wading through the attributes I see that what the second code snippet did was actually create a new attribute and set the value correctly. So in my example, when I use the second code snippet  and choose "0" for Level and then "L0spellSlot02", (even though an attribute already exists called "L0spellSlot02"), it creates a new attribute by that name and then sets the value to "Used". So now I am even more confused as I do not see any difference between the 2 attributes from a name perspective and do not understand why this is happening.
1598561313
GiGs
Pro
Sheet Author
API Scripter
Attributes are not identified by their name in the roll20 backend. They each have a unique id. It can sometimes happen when creating manually attributes through the Attributes & Abilities tab, and also using scripts or the character sheet to create attributes, that you might create two separate attributes with the same name. Roll20 sees them as different attributes because they have different ids. This used to be fairly common in the past, but rarely happens now. But because of this danger, it's best not to create attributes manually on the attributes & abilities tab. If you are using a character sheet, it supersedes that tab, and that tab becomes inaccurate and incomplete. It's fine to use when you aren't using a character sheet, but when you are using a character sheet (or api scripts), it's best to let the sheet (and script) handle it and dont create attributes manually. What I would recommend is scrubbing the sheet you've been testing on, create a new character sheet, copy over what you need, but do not create any attributes manually. Do them all through the script or character sheet. (Also, though its not relevant here, avoid attributes whose names that begin with integer just to be safe). 
1598641458

Edited 1598686137
Jakob
Sheet Author
API Scripter
So, if I remember my code correctly (and from a short inspection), ChatSetAttr should canonicalize all attribute names to uppercase and match your existing attribute if it matches up to case, so I'm not sure why it is creating a new one. One reason could be weird unicode characters, but I don't really know any other reason. (It would be possible to insert some debugging statements here, though I really should just rewrite the whole damn thing ...) Oh, if for some strange reason an attribute already exists twice, it would take the latest one, but it shouldn't create anything that does not exist yet. I would generally encourage any sheet author to name attributes in lower_snake_case because anything else is just too confusing given how Roll20 does not care about attribute case most  of the time nor strictly enforces that two attributes with the same name do not exist. What happens if you delete the first attribute from the attributes & abilities tab (not the one created by CSA, the other one), and close and reopen the sheet? What is displayed in the sheet input corresponding to this attribute? Second question, if you change the input value on the sheet, then close and reopen it, what do you see on the attributes & abilities tab, is there also a duplicate attribute or is the value of the attribute originally created by CSA changed to the new value?
1598923881

Edited 1598923926
Ok, hopefully I am doing everything that you are asking: 1) Created manual attribute lvl_0_spell_slot01, set value to "Detect Magic" 2) Modified it to "Read Magic" using: !setattr {{ --sel --?{Slot|lvl_0_spell_slot01|lvl_0_spell_slot02|lvl_0_spell_slot03|lvl_0_spell_slot04}|?{Spell|Detect Magic|Read Magic|Daze|Arcane Mark|Used} }} 3) The value changed without closing/reopening the sheet and remained set correctly after closing/reopening. 4) Modified it to "Used" using: /w gm "@{selected|character_name}" ?{Level| 0,?{Spellslot| lvl_0_spell_slot01| lvl_0_spell_slot02| lvl_0_spell_slot03| lvl_0_spell_slot04} | 1,Dork } [CAST](!setattr {{ --sel --?{Spellslot}|Used }} ) 5) The value did not change on the open sheet. Upon reopening, a new attribute having the same name had been created and its value had been set to "Used". The original attribute remained unchanged. 6) Manually changing either value and then closing/reopening the sheet had no effect (i.e. the value that was set manually remained set).
One more experimental data point: When I went back in and used this snippet: /w gm "@{selected|character_name}" [CAST](!setattr --sel --lvl_0_spell_slot01|Used) The original attribute created manually, was the one that was changed, while the one created/set by CSA with similar code was unchanged. My head is about to explode...
1599000769
Jakob
Sheet Author
API Scripter
Can you paste the exact text you are using in your command? Maybe use pastebin or something, it's really hard to understand what the command in 4) is supposed to be. It's probably something with the query which messes up the actual attribute name, especially given the fact that the simple command in your second reply works, but it's hard to tell what you are actually sending since the forum completely destroys the formatting.
Ok, so just some commentary, the "Dork" is just a placeholder for the first level spell slots once I get the 0 level spell slots working. Here is the text exactly as it appears in the Ability: /w gm "@{selected|character_name}" ?{Level| 0,?{Spellslot| lvl_0_spell_slot01| lvl_0_spell_slot02| lvl_0_spell_slot03| lvl_0_spell_slot04} | 1,Dork } [CAST](!setattr {{ --sel --?{Spellslot}|Used }} )
1599067240
Jakob
Sheet Author
API Scripter
it's as I thought. ChatSetattr sees "\nlvl_0_spell_slot02" as the name, because your query contains a newline at the start of the attribute name. It can't match that to any existing attribute, because the attributes on the sheet do not contain a new line. You cannot see it on Attributes & Abilities page because the inputs there do not display newline characters. Solution: Do not put a newline into your attribute name.
1599107178
GiGs
Pro
Sheet Author
API Scripter
Jakob, obviously this is a roll20 query issue, but is there any chance chatsetattr could be modified to trim out newline characters from attribute names? Making queries in that format is really common and convenient, and I'm pretty sure newline characters are never intended in attribute names (especially if they are at the very start).
1599157238
Jakob
Sheet Author
API Scripter
Yeah, good point. Let me submit something that trims all attributes. For the moment, you can fix this by moving the "--" into the query instead of having it external, because then the newline comes before the double-dash and the parsing works correctly.