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

Powercard PreProcessor

I once had a script that could call the PowerCard.Process function and have it process a passed in PowerCard message object.  However, it doesn't seem to work anymore.  I'm now getting a "PowerCard not defined" error.  Reference this link to see what I'm talking about.  I do have the PowerCards script and it is enabled.  It has been a few years so maybe things have changed a bit in this area?
1530933463
The Aaron
Pro
API Scripter
If you add this as the second to the last line in the current version of PowerCards: return { Process: PowerCard.Process }; and use this version of PCPP: // Github: <a href="https://github.com/shdwjk/Roll20API/blob/master/PCPP/PCPP.js" rel="nofollow">https://github.com/shdwjk/Roll20API/blob/master/PCPP/PCPP.js</a> // By: The Aaron, Arcane Scriptomancer // Contact: <a href="https://app.roll20.net/users/104025/the-aaron" rel="nofollow">https://app.roll20.net/users/104025/the-aaron</a> var PCPP = PCPP || (function() { 'use strict'; var version = '0.3.2', lastUpdate = 1530933316, schemaVersion = 0.1, powerCardFunction = function() { }, checkInstall = function() { log('-=&gt; PCPP v'+version+' &lt;=- ['+(new Date(lastUpdate*1000))+']'); if("undefined" !== typeof PowerCard &amp;&amp; _.isFunction(PowerCard.Process)) { powerCardFunction = PowerCard.Process; } else if("undefined" !== typeof PowerCardScript &amp;&amp; _.isFunction(PowerCardScript.Process)) { powerCardFunction = PowerCardScript.Process; } else if("undefined" !== typeof PowerCards &amp;&amp; _.isFunction(PowerCards.Process)) { powerCardFunction = PowerCards.Process; } else { log('No Powercard Script Found.'); } }, handleInput = function(msg_orig) { var msg=_.clone(msg_orig), args, postMap, preMap={}, expr, player_obj = getObj("player", msg.playerid); if (msg.type !== "api") { return; } args = msg.content.split(/\s+/); switch(args[0]) { case '!pcpp': // Get the API Chat Command msg.who = msg.who.replace(" (GM)", ""); msg.content = msg.content.replace("(GM) ", ""); msg.content = msg.content.replace(/&lt;br\/&gt;\n/g, ' ').replace(/({{(.*?)}})/g," $2 "); postMap = _.reduce( msg.content.match(/\[#\[(.*?)\]#\]/g), function(gmap,g){ var attrmap=_.reduce(g.match(/@#\{(.*?)\}/g), function(amap,a){ var parts=a.match(/@#\{([^|]*)\|([^\|]*)\|?(.*)?\}/), character = findObjs({ type:'character', name: parts[1] })[0], attr; amap[a]=0; if(character) { attr = findObjs({ type: 'attribute', characterid: character.id, name: parts[2] })[0]; if(attr) { amap[a]=attr.get(parts[3]==='max'?'max':'current'); } } return amap; },{}); attrmap['[#[']='[['; attrmap[']#]']=']]'; gmap[g]=_.reduce(attrmap,function(gmemo,v,k){ return gmemo.replace(k,v); },g); return gmap; },{}); postMap = _.reduce( msg.content.match(/\[=\[(.*?)\]=\]/g), function(gmap,g){ var attrmap=_.reduce(g.match(/@#\{(.*?)\}/g), function(amap,a){ var parts=a.match(/@#\{([^|]*)\|([^\|]*)\|?(.*)?\}/), character = findObjs({ type:'character', name: parts[1] })[0], attr; amap[a]=0; if(character) { attr = findObjs({ type: 'attribute', characterid: character.id, name: parts[2] })[0]; if(attr) { amap[a]=attr.get(parts[3]==='max'?'max':'current'); } } return amap; },{}); attrmap['[=[']='[['; attrmap[']=]']=']]'; preMap[g]=true; gmap[g]=_.reduce(attrmap,function(gmemo,v,k){ return gmemo.replace(k,v); },g); return gmap; },postMap); expr=_.reduce(postMap,function(m,g){return m+g;},'').replace(/\s+/g,''); if(expr) { sendChat('',expr,function(res){ var num = (msg.inlinerolls &amp;&amp; msg.inlinerolls.length) || 0, extraInlineRolls = _.toArray(res[0].inlinerolls); msg.inlinerolls = msg.inlinerolls || []; msg.content=_.reduce(postMap,function(msgCon,v,k){ var roll = extraInlineRolls.shift(); if(preMap[k]) { return msgCon.replace(k, ((roll.results &amp;&amp; roll.results.total) || '') ); } msg.inlinerolls.push(roll); return msgCon.replace(k,'$[['+(num++)+']]'); },msg.content); powerCardFunction(msg,player_obj); }); } else { powerCardFunction(msg,player_obj); } break; } }, registerEventHandlers = function() { on('chat:message', handleInput); }; return { CheckInstall: checkInstall, RegisterEventHandlers: registerEventHandlers }; }()); on('ready',function() { 'use strict'; PCPP.CheckInstall(); PCPP.RegisterEventHandlers(); }); It should work as it did before... If it does, I'll send a pull request to PowerCards and push the change up on PCPP.
1530965255

Edited 1530965420
Oh, duh!&nbsp; Even though I had linked to that forum post, PCPP totally slipped my mind. :-P&nbsp; However, I still don't have something quite wired right. Let me confirm I have things where they need to be.&nbsp; So in PowerCards, that return should be at the bottom of the script, just before the end? .map(a =&gt; a[1]))]; const repRowIds = [...new Set(repOrder.filter(x =&gt; unorderedIds.includes(x)).concat(unorderedIds))]; return [repRowIds, repeatingAttrs]; } return { Process: PowerCard.Process }; }()); Then just have PCPP installed and enabled?&nbsp; I see everything initializing, just fine on sandbox start up, but it's still crying that it can't see PowerCards from my script. This is how I'm calling out to PC. PowerCard.Process(pcMsg, playerObj); As always, I really appreciate yours and other's help, Aaron!
1530970735

Edited 1530970859
Kurt J.
Pro
API Scripter
One of the first things I did with PowerCards was to encapsulate the whole thing in a function... That is likely why the old PCPP isn't finding it. I tried out the above, and was able to process a card thru PCPP and have it displayed, so I'm going to add the exposure of the Process function as above to the next version of the script. Craig L. said: This is how I'm calling out to PC. PowerCard.Process(pcMsg, playerObj); The name of the object returned is PowerCards (with an s on the end) - because PowerCard is used internally to refer to the card that is being built/displayed. If you change to: &nbsp; &nbsp; PowerCard s .Process(pcMsg, playerObj); You'll likely be OK. This is why in The Aaron's PCPP script he goes through several iterations looking for what the script is called :)
One of the first things I did with PowerCards was to encapsulate the whole thing in a function... That is likely why the old PRPC isn't finding it. I tried out the above, and was able to process a card thru PCPP and have it displayed, so I'm going to add the suggested line above to the next version of the script. Craig L. &nbsp;said: This is how I'm calling out to PC. PowerCard.Process(pcMsg, playerObj); The name of the object returned is PowerCards (with an s on the end) - because PowerCard is used internally to refer to the card that is being built/displayed. If you change to: &nbsp; &nbsp; PowerCard s .Process(pcMsg, playerObj); You'll likely be OK. This is why in The Aaron's PCPP script he goes through several iterations looking for what the script is called :) Yep, that was it.&nbsp; If I would have slowed down a bit more, I would have caught that. ;-)&nbsp; Thanks to you both!
1530975484
The Aaron
Pro
API Scripter
Good deal!&nbsp; Glad you got it working Craig!&nbsp; Thanks for exposing the interface, Kurt!&nbsp; I'll go ahead and push PCPP up.
1530977100
Kurt J.
Pro
API Scripter
I updated the development GIST and the one-click install version.
Wait...a preprocessor? How did I miss this?&nbsp;
What exactly does this allow it to do?
1531063782
The Aaron
Pro
API Scripter
It's an older script, it's intent was to allow you to expand rolls and attribute references on the API side, rather than the Client side. !some script that changes @{someChar|SomeAttr} !pcpp --name|something --Calc on API|[#[ 1d6 + @#{someChar|SomeAttr} ]#] --static calc num[=[1d4]=]|is good It's primarily useful when you have one script that is making manipulations to a character/attribute and you want to reference the new version of that attribute in the output of your powercard. Basically: [#[ ]#] is an inline roll that is evaluated on the API side. [=[ ]=] is the same, but it will only appear as a number, not as the formula that generated it (a good way to hide the roll). @#{ } is a reference to an attribute that is expanded on the API side, so as to pick up the changed value. I tried to find an old thread that talks about it, but it's hard.&nbsp; Here's one: •&nbsp; <a href="https://app.roll20.net/forum/post/1793309/script-powercards-2-thread-2/?pageforid=1803722#post-1803722" rel="nofollow">https://app.roll20.net/forum/post/1793309/script-powercards-2-thread-2/?pageforid=1803722#post-1803722</a>
Ah, I misunderstood. I thought it was a function that allowed us to create Powercards automatically. :) There were one for 4e that was very useful. But I've yet to see one for 5e.