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

I hate scripts!

Ok so I had a perfectly nice running set of scripts, and then I added a new one, and its all fallen apart. I have had to strip out nearly everything and I am still having issues.  So currently I am getting an error with PowerCards and  the following Aaron code: SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode This was working fine, but when I added a new script it all went funny.  Can I get any comments on whether this block of code relates to the above error. And any opinions on why PowerCards_Version = "3.2.18"; would do this (it isnt the first time either but the last time it suddenly went away). on('ready',function(){     "use strict";     var regex = {         stripSingleQuotes: /'([^']+(?='))'/g,         stripDoubleQuotes: /"([^"]+(?="))"/g     };     on('chat:message',function(msg){         var args,errors=[],who,cmd,characterid,createAttrs,character;         if('api' === msg.type && msg.content.match(/^!gsa\b/) ){             if(_.has(msg,'inlinerolls')){                 msg.content = _.chain(msg.inlinerolls)                     .reduce(function(m,v,k){                         var ti=_.reduce(v.results.rolls,function(m2,v2){                             if(_.has(v2,'table')){                                 m2.push(_.reduce(v2.results,function(m3,v3){                                     m3.push(v3.tableItem.name);                                     return m3;                                 },[]).join(', '));                             }                             return m2;                         },[]).join(', ');                         m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0;                         return m;                     },{})                     .reduce(function(m,v,k){                         return m.replace(k,v);                     },msg.content)                     .value();             }             args = msg.content                 .replace(/<br\/>\n/g, ' ')                 .replace(/(\{\{(.*?)\}\})/g," $2 ")                 .split(/\s+--/);             cmd=args.shift().split(/\s+/);             characterid=_.last(cmd);             createAttrs=_.contains(cmd,'-c');             character=findObjs({                 type: 'character',                 id: characterid             })[0];                          if(character){                 let control = character.get('controlledby').split(/,/);                 if(playerIsGM(msg.playerid) || _.contains(control,'all') || _.contains(control,msg.playerid)) {                     _.chain(args)                         .map(o=>{                             let p=o.match(/("[^"]*"|'[^']'|.*?)[\|#]("[^"]*"|'[^']'|.*)/),                             a,v;                             if(p){                                 return {                                     attrName: p[1],                                     value: p[2].replace(regex.stripSingleQuotes,'$1').replace(regex.stripDoubleQuotes,'$1')                                 };                             } else {                                 errors.push({                                     type: 'BadArgument',                                     value: o                                 });                             }                         })                         .reject(_.isUndefined)                         .map(o=>{                             o.attr=findObjs({                                 type: 'attribute',                                 characterid: characterid,                                 name: o.attrName                             })[0];                             if(o.attr){                                 return o;                             } else if(createAttrs){                                 createObj('attribute',{                                     characterid: characterid,                                     name: o.attrName,                                     current: o.value                                 });                             } else {                                 errors.push({                                     type: 'MissingAttribute',                                     value: o.attrName                                 });                             }                         })                         .reject(_.isUndefined)                         .each(o=>{                             o.attr.set({                                 current: o.value                             });                         });                 } else {                     errors.push({                         type: 'NoCharacterAccess',                         value: 'You are not allowed to access this character.'                     });                 }             } else {                 errors.push({                     type: 'MissingCharacter',                     value: characterid                 });             }             if(errors.length){                 who=getObj('player',msg.playerid).get('_displayname');                 sendChat('GSA',`/w "${who}" <div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"><div style="background-color: #ffeeee;">Errors:</div>`+                     _.chain(errors)                         .map(e=>{                             return `<div><b>${e.type}</b> ${e.value}</div>`;                         })                         .value()                         .join('') +                     `</div>`);             }         }     }); });
1468904253
Lithl
Pro
Sheet Author
API Scripter
The anonymous function in your chat:message event ought  to inherit the strict mode from the anonymous function in your ready event. However, try making you chat:message explicitly strict just in case. It would be an easy fix if that is in fact the problem =)
Sorry but you will need to spell that out for me :) After reloading some scripts I am now getting -  SyntaxError: Unexpected token * Again it seems to be triggered by the above. The really annoying thing is that it was working, I wish they had a rollback feature... Vaguely related, has anyone noted that if you use the One Click feature and then delete some of the scripts you get multiple copies of them if you try to reinstall it again? VectorMath, PathMath etc don't seem to get deleted cleanly.
Added the  on('chat:message',function(msg){ "use strict"; If that is what you were indicating.  I am still now left with the token error.
Is it possible that the order of the scripts is important, and can you arrange them? Is there some logic in their order?
1468907422
The Aaron
Pro
API Scripter
Try adding a ; at the beginning of the script (as the first character before 'on'). If that doesn't work, feel free to PM me an invite and I'll come track down the issue for you.  vector math, et al are required scripts that get installed automatically. I think I read where having more that one script that declared them as required would lead to duplicates. It doesn't surprise me that not all if them get cleaned up. 
1468907623
The Aaron
Pro
API Scripter
It is possible the order is important. The scripts are all concatenated behind the scenes. If someone left off a closing ; the concatenation can lead to incorrect code which usually manifests as a syntax error.  Yours says the * a an invalid character. See if one of your scripts begins with a C-style comment ( /* */ ) that's missing it's leading /. 
Now getting: SyntaxError: Illegal return statement ;on('ready',function(){ "use strict"; Powercards has one of those... would that matter?
I have to leave work, will try to get to you in about an hour, thanks.
1468907819
The Aaron
Pro
API Scripter
The one in Powercards is to prevent concatenation errors. It's 1:00am here. If you PM me an invite, I'll join in the morning and you can GM me. 
Might have aproblem with timezone, 4pm here-1am, so 11pm=8am... give me a time and I will try to be there, thnks.
As for the order of the scripts, how can you reorder them?  It doesnt seem to be alphabetical, do you just dlete them all and then re-add then in the order you want?
1468909733
The Aaron
Pro
API Scripter
You can't easily affect the order, you just have to fix the problem. :)
1468916959
Ziechael
Forum Champion
Sheet Author
API Scripter
The only sure fire way to affect the order is to manually concatenate them yourself into one long glorious script (which I had to do once when mine started playing up back in the olden days). The issue with that is that: It's a pain in the first place It makes updating scripts awkward as you have to find them and replace the right code with the updated version You can't take advantage of the one click install and maintain your preferred order Which is why I usually opt for: The Aaron said: You can't easily affect the order, you just have to fix the problem. :) And to do that, I ask Aaron ;)
1468979280
The Aaron
Pro
API Scripter
Fixed. &nbsp;It was a two-fold problem: 1) &nbsp;Your copy of StatusTracker was strangely corrupted. &nbsp;I believe it's the result of the Raw view of the file on github rendering strangely and very much NOT in a raw manner (likely the file type is misinterpreted. 2) &nbsp;This:&nbsp; <a href="https://app.roll20.net/forum/post/1028853/bug-sugg" rel="nofollow">https://app.roll20.net/forum/post/1028853/bug-sugg</a>... &nbsp; &nbsp; PowerCards ends with a C++ style comment and no newline: // END FUNCTIONS /////////////////////////////////////////////////////////////// When the API concatenates all the scripts together, the next script (GroupSetAttr) begins like this: on('ready',function(){ Resulting in this line: // END FUNCTIONS ///////////////////////////////////////////////////////////////on('ready',function(){ Effectively commenting out the start of the script and leaving a trailing } that crashes the API, or some other character depending on what the next script is. &nbsp;In the case where the next script starts with a blank line, or another C++ style comment, the error doesn't occur. &nbsp;The fix for this is to add a carriage return after the comment, or switch the final comment to a C style comment, so that it isn't commenting out the whole line (including the concatenated next script's first line). &nbsp;I'll ping HoneyBadger about it.
Thank you so much.&nbsp;
The powercards gist has been updated as per TheAaron's fix. Just fyi.
1468985577
The Aaron
Pro
API Scripter
HB is my hero! No problem Kevin, Happy Rolling!
One slight issue, I tried setting a Patrol path and get the following: TypeError: TokenCollisions.getFirstCollision is not a function TypeError: TokenCollisions.getFirstCollision is not a function at getTrapCollision (apiscript.js:3278:30) at apiscript.js:3357:22 at eval (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:105:34), &lt;anonymous&gt;:65:16) at Object.publish (eval at &lt;anonymous&gt; (/home/node/d20-api-server/api.js:105:34), &lt;anonymous&gt;:70:8) at TrackedObj.set (/home/node/d20-api-server/api.js:704:14) at updateLocalCache (/home/node/d20-api-server/api.js:933:18) at /home/node/d20-api-server/api.js:1076:11 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147) at Kd (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:546) It might be I am using it wrong, but I did what it says to do... plot a move and click the Path button... &nbsp;It isnt a huge deal.
Ignore me, its what I am doing that is an issue...
1469070742
Ada L.
Marketplace Creator
Sheet Author
API Scripter
Sounds like TokenCollisions isn't installed. If you've installed It's A Trap, it should have installed that automagically as a dependency. I can't find that Patrol script in the API repo.Does that one depend on It's A Trap?
The Patrol by Waypoints isnt listed in the API, but the problem was Token Collision, I was using manual version, changed to OneClick and all good.