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

A Little Help Adding Actions? 5E OGL

1546045611

Edited 1547500740
Bast L.
API Scripter
Edit: Solved. Extra parentheses in repstring.  Hello. I'm trying to write a parser for importing NPCs from a pdf of Rappan Athuk, since it has so many monsters. Anyways, I'm stuck adding actions. I figured it might be some weird problem, so I made a simpler version to add an action seen below. The result is, for an NPC using the 5E OGL sheet, it adds 2 actions, one being the one specified by the script, which is not functional (clicking on it does nothing), the other being a blank action before it, which is clickable. This replicates the problem I have in the larger script. I copied the generateUUID and generateRowID code from another thread, which seemed to work on other sheets I've tried it on (adding weapons and such). //ActionMaker Test var generateUUID = ( function () { "use strict" ; var a = 0 , b = []; return function () { var c = ( new Date ()). getTime () + 0 , d = c === a ; a = c ; for ( var e = new Array ( 8 ), f = 7 ; 0 <= f ; f --) { e [ f ] = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" . charAt ( c % 64 ); c = Math . floor ( c / 64 ); } c = e . join ( "" ); if ( d ) { for ( f = 11 ; 0 <= f && 63 === b [ f ]; f --) { b [ f ] = 0 ; } b [ f ]++; } else { for ( f = 0 ; 12 > f ; f ++) { b [ f ] = Math . floor ( 64 * Math . random ()); } } for ( f = 0 ; 12 > f ; f ++){ c += "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" . charAt ( b [ f ]); } return c ; }; }()), generateRowID = function () { "use strict" ; return generateUUID (). replace ( /_/ g , "Z" ); }; on ( "ready" , function () { on ( "chat:message" , function ( msg ) { if ( msg . type === "api" && msg . content === "!ActionMakeTest" ) { ActionTest ( msg ); } }); }); function ActionTest ( msg ) { let reps = getObj ( msg . selected [ 0 ]. _type , msg . selected [ 0 ]. _id ). get ( 'represents' ); let actionObj = { name: "blah" , description: "bobloblaw" } const repString = `repeating_npcaction_ ${ generateRowID () } )` ; const data = {}; Object . keys ( actionObj ). forEach ( field => { data [ ` ${ repString } _ ${ field } ` ] = actionObj [ field ]; }); setAttrs ( reps , data ); } Result (2 actions, first is blank and works, second is desired action name and body, does not click):
Or, forgetting the method I'm using, if someone knows how to add actions to 5E OGL NPC sheets via the API, I'd be interested to find out your method.
1546362580
The Aaron
Pro
API Scripter
setAttrs() is usually a sheetworker function. I know it’s been ported for compatibility, but I’ve not used it. Just to rule out any sort of non-obvious dependency on other sheetworker functions, I’d suggest rewriting that part as a series of createObj() calls to make the attributes. 
I guess I'm not sure how to even add an action to the NPC without using setAttrs. I mean on the sheet page, not the attributes and abilities page. I did use this section of the wiki to make a blank action using setAttrs, but it was both non-clickable, and strangely, non-deletable. 
1546486252

Edited 1546486707
The Aaron
Pro
API Scripter
I’ll have to type an example when I’m on my computer, but you’re just using something like: createObj('attribute',{ name: `repeating_npcaction_${generateRowID()}_${field}`, current: actionObj[field]});
1546500209
Jakob
Sheet Author
API Scripter
The Aaron said: I’ll have to type an example when I’m on my computer, but you’re just using something like: createObj('attribute',{ name: `repeating_npcaction_${generateRowID()}_${field}`, current: actionObj[field]}); This might interact in problematic ways with sheet workers. It's probably better to first create the attribute empty, then set it to the desired value with setWithWorkers().
1546517758
The Aaron
Pro
API Scripter
Great point!
1546545066

Edited 1546545254
Bast L.
API Scripter
So, I can't seem to find anything on setWithWorkers in the wiki, and when I tried guessing how to use it, the console said it was undefined.
1546545847
The Aaron
Pro
API Scripter
It’s identical to Thing.set(), but kicks off the sheet workers. 
1546545972
The Aaron
Pro
API Scripter
Original announcement post:&nbsp; <a href="https://app.roll20.net/forum/post/4507273/new-api-update-sheet-worker-support-in-api-scripts-speed-improvements/?pageforid=4507273#post-4507273" rel="nofollow">https://app.roll20.net/forum/post/4507273/new-api-update-sheet-worker-support-in-api-scripts-speed-improvements/?pageforid=4507273#post-4507273</a>
Ok, I was typing "setWithWorkers", not "setWithWorker", lol. So much frustration with this. Thanks for helping out so far guys. Anyways, I've gotten back to the state where I was at the beginning: it makes 2 actions, 1 blank which is clickable, 1 filled out which is not. //ActionMaker Test var generateUUID = ( function () { "use strict" ; var a = 0 , b = []; return function () { var c = ( new Date ()). getTime () + 0 , d = c === a ; a = c ; for ( var e = new Array ( 8 ), f = 7 ; 0 &lt;= f ; f --) { e [ f ] = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" . charAt ( c % 64 ); c = Math . floor ( c / 64 ); } c = e . join ( "" ); if ( d ) { for ( f = 11 ; 0 &lt;= f &amp;&amp; 63 === b [ f ]; f --) { b [ f ] = 0 ; } b [ f ]++; } else { for ( f = 0 ; 12 &gt; f ; f ++) { b [ f ] = Math . floor ( 64 * Math . random ()); } } for ( f = 0 ; 12 &gt; f ; f ++){ c += "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" . charAt ( b [ f ]); } return c ; }; }()), generateRowID = function () { "use strict" ; return generateUUID (). replace ( /_/ g , "Z" ); }; on ( "ready" , function () { on ( "chat:message" , function ( msg ) { if ( msg . type === "api" &amp;&amp; msg . content === "!ActionMakeTest" ) { ActionTest ( msg ); } }); }); function ActionTest ( msg ) { let reps = getObj ( msg . selected [ 0 ]. _type , msg . selected [ 0 ]. _id ). get ( 'represents' ); const actionObj = { name: "Fuh" , description: "Blahblah" , attack_flag: "0" , }; const repString = `repeating_npcaction_ ${ generateRowID () } )` ; Object . keys ( actionObj ). forEach ( field =&gt; { createObj ( 'attribute' , { name: ` ${ repString } _ ${ field } ` , characterid: reps }); }); Object . keys ( actionObj ). forEach ( field =&gt; { findObjs ({ _type: "attribute" , name: ` ${ repString } _ ${ field } ` , characterid: reps })[ 0 ]. setWithWorker ({ current: actionObj [ field ]}); }); }
As usual, a simple stupid error tripped me up. There's an extra parentheses in my repstring, at the end there. Adding actions works fine now :)
1547506775
The Aaron
Roll20 Production Team
API Scripter
Great!