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

[5E OGL] [HELP] setWithWorker on _hasattack attribute not adding the item to Attacks and Spellcasting section

August 10 (5 years ago)

Edited August 10 (5 years ago)


I want to use a script that sends the items that are equipped and that has attack to chat with hyperlinks to toggle the equipped and has an attack checkbox.


The toggles work fine, and if the items is already in the Attack and Spellcasting section and that I toggle has an attack off, it properly removes the item from the section. 


But, when I toggle it back, the checkboxes check themselves, but the item doesn't automatically go back to the Attack and Spellcasting section.


FROM CONSOLE --> 

*****************************************************************************************************************************************************************

"ReferenceError: update_attacks is not defined\n    at Array.eval (eval at messageHandler (evalmachine.<anonymous>:284:6), <anonymous>:240:13)\n    at self.trigger (evalmachine.<anonymous>:79:37)\n    at messageHandler (evalmachine.<anonymous>:287:11)\n    at process.<anonymous> (/home/node/d20-api-server/node_modules/tiny-worker/lib/worker.js:65:55)\n    at emitTwo (events.js:106:13)\n    at process.emit (events.js:194:7)\n    at process.nextTick (internal/child_process.js:766:12)\n    at _combinedTickCallback (internal/process/next_tick.js:73:7)\n    at process._tickCallback (internal/process/next_tick.js:104:9)"

*****************************************************************************************************************************************************************


Any help would be greatly appreciated. 


*** I use this for player to swap their weapons and be able to attack with them. If it is not equipped, can't attack with it. Now, if you have 2 hands, you will have to use a bonus action to swap weapons, and if the weapon needs your hands to be used, there shouldn't be more than two weapons in that section.



August 10 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

You said you are using a script. What script are using, and can you post its code?

August 10 (5 years ago)

I use oukag/5eOGLInventoryTracker.js

--> https://gist.github.com/oukag/bf92a517e7dfb2f1ce94b0e46e695d92


To which I added : 

To the object ITEM --> 

 HASATTACK_SUFFIX : '_hasattack', 

HASATTACK : '1',

HASNOATTACK : '0',


and then mostly duplicated existing functions to add the verification and 'toggling' of the HAS AN ATTACK checkbox within the sheet.


It does the checking and unchecking of the boxes fine, but doesnt automatically update the Attacks and Spellcasting section. Only does when I go manually check the box or when untoggling. 

So, Untoggling the HAS AN ATTACK checkbox through the script while the item is in the Attacks and Spellcasting section does remove the item from the section. But toggling the HAS AN ATTACK checkbox through the script while the item is not in the Attacks and Spellcasting won't succesfully put it back in the section.

August 10 (5 years ago)

I should add that the above Console Message occurs when Untoggling the HAS AN ATTACK checkbox through the script while the item is in the Attacks and Spellcasting. Although it does remove it from Attacks and Spellcasting lol

August 10 (5 years ago)

Edited August 10 (5 years ago)

Will also add that I use the companion script. I see update_attacks function all over 


https://github.com/Roll20/roll20-api-scripts/commit/d349d758f8e98a0051fd6a22070e27c3abb78dd7

Companion 5e OGL 1.4.1 ^^


--> https://gist.github.com/SteveKoontz/7dce834b2285734d8f557f03489531c2



*** EDIT **

Here? It seems to ignore modifications from the sheetworker

    on("change:repeating_inventory:hasattack", function(eventinfo) {

        if(eventinfo.sourceType === "sheetworker") {

            return;

        }


        var itemid = eventinfo.sourceAttribute.substring(20, 40);

        getAttrs(["repeating_inventory_" + itemid + "_hasattack", "repeating_inventory_" + itemid + "_itemattackid"], function(v) {

            var attackid = v["repeating_inventory_" + itemid + "_itemattackid"];

            var hasattack = v["repeating_inventory_" + itemid + "_hasattack"];

            if(attackid && attackid != "" && hasattack == 0) {

                remove_attack(attackid);

            }

            else if(hasattack == 1) {

                create_attack_from_item(itemid);

            };

        });

    })

August 10 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter


Jocelyn C. said:

I use oukag/5eOGLInventoryTracker.js

--> https://gist.github.com/oukag/bf92a517e7dfb2f1ce94b0e46e695d92


To which I added : 

To the object ITEM --> 

 HASATTACK_SUFFIX : '_hasattack', 

HASATTACK : '1',

HASNOATTACK : '0',


and then mostly duplicated existing functions to add the verification and 'toggling' of the HAS AN ATTACK checkbox within the sheet.


It does the checking and unchecking of the boxes fine, but doesnt automatically update the Attacks and Spellcasting section. Only does when I go manually check the box or when untoggling. 

So, Untoggling the HAS AN ATTACK checkbox through the script while the item is in the Attacks and Spellcasting section does remove the item from the section. But toggling the HAS AN ATTACK checkbox through the script while the item is not in the Attacks and Spellcasting won't succesfully put it back in the section.


Can you post the version of this script you're using, with your modifications? Maybe in a pastebin or gist rather than here.

August 10 (5 years ago)

I have noticed when inspecting the repeating section in the browser dev tool that the attribute itemattackid 'renews' itself when you manually check the HAS AN ATTACK checkbox. It doesn't when you check the box with the sheeyworker. That, I assume, is why it doesn't go back in the Attack and Spellcasting section


August 11 (5 years ago)

Edited August 11 (5 years ago)

Does this work? just created free account and didn't really read but saw it said you need a readme and etc...


https://github.com/Gauzin/ROLL20/blob/0.1/SheetToChat.js






August 11 (5 years ago)

Edited August 11 (5 years ago)

And the hasattack value stays 1 when unchecking box with script. I can't even get it to go back to 0, even manually checking or unchecking the box. Even when refreshing the page.  Something is bad here :/ good thing I created 2 copies of this game. :D


Nevermind this ^^ it actually changes the value. Brain lag involved

August 11 (5 years ago)

Edited August 11 (5 years ago)

I want to add that other MODS properties of items are updating the corresponding attributes correctly upon equipping and unequipping from script (AC, Ac+, Stength+, etc...) although I now got additional reference errors from the console

-->

"ReferenceError: update_weight is not defined"

"ReferenceError: update_weight is not defined\n    at Array.eval (eval at messageHandler (evalmachine.<anonymous>:284:6), <anonymous>:150:37)\n    at self.trigger (evalmachine.<anonymous>:79:37)\n    at messageHandler (evalmachine.<anonymous>:287:11)\n    at process.<anonymous> (/home/node/d20-api-server/node_modules/tiny-worker/lib/worker.js:65:55)\n    at emitTwo (events.js:106:13)\n    at process.emit (events.js:194:7)\n    at process.nextTick (internal/child_process.js:766:12)\n    at _combinedTickCallback (internal/process/next_tick.js:73:7)\n    at process._tickCallback (internal/process/next_tick.js:104:9)"

"ReferenceError: update_initiative is not defined"

"ReferenceError: update_initiative is not defined\n    at Array.eval (eval at messageHandler (evalmachine.<anonymous>:284:6), <anonymous>:151:38)\n    at self.trigger (evalmachine.<anonymous>:79:37)\n    at messageHandler (evalmachine.<anonymous>:287:11)\n    at process.<anonymous> (/home/node/d20-api-server/node_modules/tiny-worker/lib/worker.js:65:55)\n    at emitTwo (events.js:106:13)\n    at process.emit (events.js:194:7)\n    at process.nextTick (internal/child_process.js:766:12)\n    at _combinedTickCallback (internal/process/next_tick.js:73:7)\n    at process._tickCallback (internal/process/next_tick.js:104:9)"

"ReferenceError: update_attacks is not defined"

"ReferenceError: update_attacks is not defined\n    at Array.eval (eval at messageHandler (evalmachine.<anonymous>:284:6), <anonymous>:158:13)\n    at self.trigger (evalmachine.<anonymous>:79:37)\n    at messageHandler (evalmachine.<anonymous>:287:11)\n    at process.<anonymous> (/home/node/d20-api-server/node_modules/tiny-worker/lib/worker.js:65:55)\n    at emitTwo (events.js:106:13)\n    at process.emit (events.js:194:7)\n    at process.nextTick (internal/child_process.js:766:12)\n    at _combinedTickCallback (internal/process/next_tick.js:73:7)\n    at process._tickCallback (internal/process/next_tick.js:104:9)"



August 11 (5 years ago)

Here is my updated version 

--> https://github.com/Gauzin/ROLL20/blob/master/SheetToChat.js


I have added functions to : 

Show equipped armors. Hyperlink toggles equipped checkbox

Show equipped items that have attacks. Hyperlink toggles equipped and hasattack checkboxes

Show equipped items that have attacks by Attack Type Melee, Ranged or Thrown. Hyperlink will release the said template (which is my modified powercards script for now) --> IN PROGRESS

August 12 (5 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

If you think this issue might have anything to do with this thread, please post a report there as well? There's been a long standing issue with the API and Sheet Workers, and more data couldn't hurt.

August 12 (5 years ago)

Yep. Pretty much seems like it. At least, very similar to yours. Good job on tracking my post for it to get even more traction. How would you proceed in that case? Would you simply repost there what I posted here?

August 12 (5 years ago)

Edited August 12 (5 years ago)
keithcurtis
Forum Champion
Marketplace Creator
API Scripter

There are a couple of sample cases already posted in the thread. For making it simpler for the developers, maybe try to follow that format along with your findings? There's no real precedent for it, so "do as thou wilt".

August 13 (5 years ago)

Edited August 13 (5 years ago)
Allright!  Will do shortly. Thx Keith! Let's hope it resolves soon. I know you've been dealing with it longer than I did  have  :P
August 14 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

I wish i had more time to look at this, but its a pretty complex problem involving multiple scripts and a sheet I'm not familiar with.

Have you tried restoring the original versions of any scripts you've edited, for testing purposes? I'd recommend doing that, and seeing if you still get errors. 

Either way, it is probably worth asking the creators of those scripts for advice.

Your posts to github did work, btw.