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

Possible issue with ChatSetAttr API Script and character sheet Melee Weapon table?

1605436105

Edited 1605436198
Richard @ Damery
Pro
API Scripter
I have found a bug (?) in the creation of the melee weapons table on the ADnD 2e character sheet (not sure if sheet type is relevant).  I use the ChatSetAttr API Script in my macros to create the lines in the tables.  Using this line below 2 times (separate calls using an API button)  should add two rows at index $0 and $1 to the melee weapons table: !setattr --charid @{selected|character_id} --repeating_weapons_-CREATE_weaponname|Melee weapon name The entry at index $0 is created fine.  However the next time this is called, the index at $1 does not seem to be created.  @{selected|repeating_weapons_$1_weaponname} returns empty string .  So does @{selected|repeating_weapons_$2_weaponname} (even though $2 should not exist yet).  And @{selected|repeating_weapons_$3_weaponname} returns Melee weapon name  even though it really should not exist!  If I carry on adding lines, indexes are created in what appear to be groups of 3 at ever higher indexes.  The sheet appears normal when opened, but using !setattr --charid @{selected|character_id} --repeating_weapons_$1_weaponname|New weapon name sets row $3 to be New weapon name, and trying to access for instance $3 in the above example using: !setattr --charid @{selected|character_id} --repeating_weapons_$3_weaponname|New weapon name causes an error as the CharSetAttr API Script does not think row $3 exists.  There are not 5 rows visible on the character sheet when I open it, only 3, so something is odd here. The only way around it I have found is to manually use the [Modify] button on the table, and drag the last row to before the second row, then click [Done].  This seems to fix the issue, and $0 & $1 indexes then perform as expected, and $3 no longer exists. I've done some more investigation: using the [Add] button on the character sheet to manually add rows seems to work OK, if you add 3 rows (the base row with field name "weaponname", and two repeating rows at index $0 & $1) using @{selected|repeating_weapons_$1_weaponname} returns what is expected.   However , @{selected|repeating_weapons_$2_weaponname} I would expect to return the error "You tried to use the repeating section row at index 2 for repeating_weapons, but there doesn't seem to be a row at that index." but it does not - it returns  empty string .  So does $3.  Only $4 then returns the error.  This might relate to the "groups of 3" I refer to. Has anyone else come across this bug?  Is anyone able to fix it?
1605784886

Edited 1605787702
Richard @ Damery
Pro
API Scripter
Further update on this bug - and it is definitely a bug that is causing me major grief, if anyone is reading this... The same issue as with the melee weapons table above (repeating_weapons_$n_weaponname) is seen on the first column of spell book, (repeating_spells_$n_spellname), but not on any other table including the other columns of the spellbook (repeating_spells2_$n_spellname2, repeating_spells3_$n_spellname3, ...) or any of the weapon-damage, ammo, weaponprof, prof, potion or other repeating row tables. Looking at the code for ChatSetAttr v1.10 on Github, the code at line 398 & 399 is probably where the issue occurs.  My limited programming knowledge seems to indicate it sets the finalId  for the to-be-created repeating row to be the length of the array of existing rowIds -1.  However, from experimentation I know that after the first repeating row is created, 2 "ghost" rows are created (see the final paragraph in the initial post) that don't appear on the character sheet, so this will create the "every 3 rows" gaps I am seeing. Is this an API bug with ChatSetAttr, or with the ADnD 2E character sheet?  I've not tried other character sheet formats as I am not familiar with them.  I have posted the same bug to the ADnD 2E character sheet forum, and I'd love to know where the bug is and have a fix or a macro-based work-around (I know the manual one, but the other DMs I support are not so system-savvy as I am... which is why I'm programming this macro library). Please help!
1605792378
timmaugh
Pro
API Scripter
I saw a similar thing in the WoD sheet for a different repeating section. You can grab the XRay script (part of InsertArg) to walk the character sheet and see what the state of the repeating section is before/after you make an entry. (Just run !xray, then pick the character and section). When I did the WoD sheet, I found 3-4 ghost elements getting entered for each real entry I created in the section. I can think of courses of action that could possibly work around that, but every sheet might be different. If someone with a little sheet experience can explain what is happening, it might shorten the path to a solution...
OK.  I think it might be a timing thing, perhaps associated with clean-up in the sheet- workers?  If I wait 20 seconds between each row creation using !setattr, it all seems to work fine now.  Either that or, while I've been posting these error reports, someone has fixed the sheet! Whatever, I can now use !delay to force a time space between calls to !setattr to allow the sheet-workers or whatever time to wrap-up.  I'll see if that works.
1605816687
Jakob
Sheet Author
API Scripter
This is really bizarre. I can take a look by adding some extra logging (no promises, it would take some time), but it might be related to those  excruciatingly slow  sheet workers that somehow create extra rows (these sheet workers, if they are written to be slow, might be even slower when they're running in the API, which is exactly what happens when ChatSetAttr creates a row). Under no circumstance should ChatSetAttr create more than 1 row on the character sheet, especially with such a simple command, so it's likely that this is done by workers. What's strange is that I imagine that these phantom rows should show up in the character sheet somehow, I can't see how they wouldn't.
1605817932

Edited 1605817939
Andreas J.
Forum Champion
Sheet Author
Translator
As concluded in the other thread, it's indeed highly suspected it has to do with sheetworkers. <a href="https://app.roll20.net/forum/post/9493864/possible-bug-in-melee-weapon-table-of-adnd-2e-character-sheet" rel="nofollow">https://app.roll20.net/forum/post/9493864/possible-bug-in-melee-weapon-table-of-adnd-2e-character-sheet</a> , but it might be related to those&nbsp; excruciatingly slow &nbsp;sheet workers that somehow create extra rows (these sheet workers, if they are written to be slow, might be even slower when they're running in the API, which is exactly what happens when ChatSetAttr creates a row). Considering how old the sheet is, I'd say its quite likely they are slow and ineffective.
1605859255

Edited 1605865291
Richard @ Damery
Pro
API Scripter
Edit: &nbsp;FYI, this is the more complex AD&amp;D 2e sheet, and not the 2E (Simple Sheet).&nbsp; I don't know if the same problem occurs there. I've done yet more investigation, and it is ChatSetAttr that creates the extra rows (or at least triggers their creation).&nbsp; The Character Sheet is being maintained.&nbsp; See this thread (last update 11 November 2020):&nbsp;&nbsp; <a href="https://app.roll20.net/forum/post/9311682/official-ad-and-d-2e-revised-update-thread" rel="nofollow">https://app.roll20.net/forum/post/9311682/official-ad-and-d-2e-revised-update-thread</a> .&nbsp; Indeed, I've retested the issue found with using [Add+] button on the sheet, and it no longer seems to be a problem... I'm sure I was not imagining it, as I've had that issue for some time. But back to ChatSetAttr: Try this sequence: Create a blank 2E character sheet, open it to the Weapons tab and fill in the existing base melee weapon name with anything, and the 1st damage row name with anything (not sure this matters), then drag the character sheet onto the map to create a token. Make some copies of this sheet so you have fresh test subjects. Select the token on the map. If you do !setattr --sel --repeating_weapons_-CREATE_weaponname|MW1 in the chat window and then wait a while, and then do it again in the chat window, all is fine. No ghost rows seem to be created if I do sequential checks with @{selected|repeating_weapons_$n_weaponname}.&nbsp; (I tend to go into the sheet and add distinct names to the rows to make it clear). If you put in an Ability macro !setattr --sel --repeating_weapons_-CREATE_weaponname|MW1, and call that from an Token Ability Button, all is fine if you click the button slowly a couple of times. Use a new test character sheet (one of the copies you made above). If you create the following in an Ability macro, and call it from a Token Ability button and press the button twice , it creates a "ghost" row in the Melee Weapons table (you can add an incrementing counter to the macro to set different weapon numbers if you want!).&nbsp; Subsequent presses each create at 2 indexes higher (skipping 1 each time), but only in the Weapons table, not the damage table: !setattr --sel --repeating_weapons_-CREATE_weaponname|MW1 !setattr --sel --repeating_weapons-damage_-CREATE_weaponname1|Dmg1 Using a new test character sheet: there is a similar issue if you make it this, but adds two ghost rows if you call it twice &nbsp;on a new character sheet copy (with subsequent presses creating rows skipping two indexes): !setattr --sel --repeating_weapons_-CREATE_weaponname|MW1&nbsp;--repeating_weapons-damage_-CREATE_weaponname1|Dmg1 !setattr --sel --repeating_weapons2_-CREATE_weaponname2|RW1 --repeating_ammo_-CREATE_-ammoname|Ammo1 Do you get the same results? I'm not sure if this is the sheet or ChatSetAttr.
The sheet author, Peter B. , has come back to me with the following information (you can find the original post here: <a href="https://app.roll20.net/forum/permalink/9517524/" rel="nofollow">https://app.roll20.net/forum/permalink/9517524/</a> ): Generally I have no experience with API Scripting and only very little with Macros. That being said, I have had other users report problems when using macros on the sheet. On of the issues can be that the sheet does not conform to minimum requirements for a sheet when it comes to repeating sections. Specifically the problem is that many repeating sections' attributes share names with static attributes. Ie. There is both a&nbsp; static attribute &nbsp;and a&nbsp; repeating attribute&nbsp; called 'weaponname'. When using the buttons on the sheet it does not pose any problems. But when using macros to either access the attributes or roll the buttons it create problems. This could be one of the reasons why you are having problems with weapons, and the first spell column, but not the other spell columns. &nbsp;All of this is just a guess, as I have no idea how far reaching this error is. All my macros &amp; API Script programming takes this into account - it required some complex redirecting &amp; indirecting to do it, but it works &amp; is stable.&nbsp; However, ChatSetAttr is, of course, a generic script, designed to work with any standard character sheet.&nbsp; This would seem to imply that ChatSetAttr may be encountering problems relating to this issue of static vs. repeating names.&nbsp; However, many of the other repeating tables have the same mix of static &amp; repeating (e.g. the weapons-damage, weapons2, and ammo tables) and do not have the problem, which perhaps implies this is a red herring?&nbsp; And the repeating_spells_$n table does not have a mixed static &amp; repeating name issue but does have this "ghost row" problem...
1606734397

Edited 1606734590
Peter B.
Pro
Sheet Author
Richard @ Damery said: If you create the following in an Ability macro, and call it from a Token Ability button and press the button twice , it creates a "ghost" row in the Melee Weapons table (you can add an incrementing counter to the macro to set different weapon numbers if you want!).&nbsp; Subsequent presses each create at 2 indexes higher (skipping 1 each time), but only in the Weapons table, not the damage table: !setattr --sel --repeating_weapons_-CREATE_weaponname|MW1 !setattr --sel --repeating_weapons-damage_-CREATE_weaponname1|Dmg1 Using a new test character sheet: there is a similar issue if you make it this, but adds two ghost rows if you call it twice &nbsp;on a new character sheet copy (with subsequent presses creating rows skipping two indexes): !setattr --sel --repeating_weapons_-CREATE_weaponname|MW1&nbsp;--repeating_weapons-damage_-CREATE_weaponname1|Dmg1 !setattr --sel --repeating_weapons2_-CREATE_weaponname2|RW1 --repeating_ammo_-CREATE_-ammoname|Ammo1 Do you get the same results? I'm not sure if this is the sheet or ChatSetAttr. I have run into the similar issues, that making too rapid updates tends to course problems. I don't know if it the large amount of sheet workers or the large amount of auto calculating fields. I have tried my best to only use sheet workers moving forward, and convert old auto calculting fields into sheet workers as the forums has descibed that as best practice. There might be a critical mass of calculations that the sheet can handle, also since multiple sheet workers tend to read of each other to creating cascading updates throughout the sheet
1606734848
Peter B.
Pro
Sheet Author
Jakob said: This is really bizarre. I can take a look by adding some extra logging (no promises, it would take some time), but it might be related to those&nbsp; excruciatingly slow &nbsp;sheet workers that somehow create extra rows (these sheet workers, if they are written to be slow, might be even slower when they're running in the API, which is exactly what happens when ChatSetAttr creates a row). Under no circumstance should ChatSetAttr create more than 1 row on the character sheet, especially with such a simple command, so it's likely that this is done by workers. What's strange is that I imagine that these phantom rows should show up in the character sheet somehow, I can't see how they wouldn't. Hello Jakob. Just to be clear are the sheet workers you are refering to: Some internal sheet workers that create rows (controlled by Roll20 and outside the control of sheet authers) The sheet workers implemented by sheet authors to update various fields around the sheet I am trying to decipher if I need to go through the workers and look for optimizations or if this is outside my control
1609240731
Peter B.
Pro
Sheet Author
Hey&nbsp; Richard @ Damery : Did you ever find a permanent solution to this, beside just waiting between calls? I am currently experiencing the same problem, when updating the weapons row with a sheet worker.
1609260331
Peter B.
Pro
Sheet Author
Richard @ Damery &nbsp;and&nbsp; Jakob I finally found the bug, and have created a post on the Pro forum about it. Lets hope someone from Roll20 picks it up and finds out what the problem is. <a href="https://app.roll20.net/forum/permalink/9642656/" rel="nofollow">https://app.roll20.net/forum/permalink/9642656/</a>
Peter B. &nbsp;and Jakob I'm still getting the problem.&nbsp; There are also other issues that I'm discussing with The Aaron &nbsp;in this thread , around APIs accessing repeating table attribute objects reliably.&nbsp; There is a bug in getAttrByName(), and other access methods seem also to have issues.&nbsp; All in all, this is making my programming of a 2E API support suite for my fellow DMs somewhat challenging...
I wonder if this is related to the sheet worker issues that were reported last year? <a href="https://app.roll20.net/forum/post/7440478/api-no-longer-triggering-sheet-workers/?pagenum=1" rel="nofollow">https://app.roll20.net/forum/post/7440478/api-no-longer-triggering-sheet-workers/?pagenum=1</a> I don't think they were ever resolved, as I still experience issues when using either ChatSetAttr or Ammo with sheets like the DnD 5e Official and Pathfinder Official. I've run into this 'ghost row' issue in the Pathfinder 2e sheet as well when using ChatSetAttr to create rows.
1613526351

Edited 1613527382
I am still having problems with the repeating weapons for the AD&amp;D 2E Revised v3.4.0&nbsp; update after the 2nd weapon.&nbsp; Macros for weapon 1 and weapon 2 work fine, but the third one isn't working.&nbsp; So when I change the $1 to a $2 it doesn't take into account attack adjustments.&nbsp; &nbsp;Here's the macro I'm using:&nbsp; &amp;{template:2Eattack}{{title=@{selected|token_name} makes an Attack!}}{{subtitle=vs.@{target|token_name}}}{{weapon_used=@{selected|repeating_weapons-damage_$0_weaponname1}}}{{ac_hit=[[@{selected|repeating_weapons_$0_ThAC0}-((D20?{ATTACK ROLL MODIFIER|+0})+(@{selected|repeating_weapons_$0_attackadj})+(@{selected|strengthhit}*@{selected|repeating_weapons_$0_strbonus})+(@{selected|dexmissile}*@{selected|repeating_weapons_$0_dexbonus}))]]}}{{dmg_s=[[((@{selected|repeating_weapons-damage_$0_damsm}?{DAMAGE ROLL MODIFIER|+0}))+(@{selected|repeating_weapons-damage_$0_damadj})+(@{selected|strengthdmg}*@{selected|repeating_weapons-damage_$0_strbonus1})]]}}{{dmg_l=[[((@{selected|repeating_weapons-damage_$0_daml}?{DAMAGE ROLL MODIFIER|+0}))+(@{selected|repeating_weapons-damage_$0_damadj})+(@{selected|strengthdmg}*@{selected|repeating_weapons-damage_$0_strbonus1})]]}}