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

Play Card To Table Error

Towards the bottom is a snippet of the code I'm using and the error I am getting while attempting to place a deleted card back to the table.  Before the error I get a " ERROR: Please use the 'thumb' size for imgsrc properties. " message and you will see that I have tried addressing that  as per the code from here. I'm once again stuck.  Is my problem that I'm trying to play a card that is in the discard? if(obj.get('_subtype')=='card') {   var theCardID = obj.get('_cardid');   //   obj.set('imgsrc',getCleanImgsrc(obj.get('imgsrc')));   //   obj.set('sides',getCleanImgsrc(obj.get('sides')));   playCardToTable(theCardID,{left: 100, top: 100}); } For reference, the error message generated was:  TypeError: Cannot read property 'set' of undefined TypeError: Cannot read property 'set' of undefined at playCardToTable (/home/node/d20-api-server/api.js:2492:9) at handleGraphicDestruction (apiscript.js:7893:9) at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:154:1), <anonymous>:70:8) at TrackedObj.destroy (/home/node/d20-api-server/api.js:1264:10) at deleteFromLocalCache (/home/node/d20-api-server/api.js:1388:18) at /home/node/d20-api-server/api.js:1526: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)
Without the larger context, it's not clear what you want to achieve and what might go wrong. Also the offending line seems to be commented out. 
Thank you for the response.  I'm simply trying to put a just deleted card back on the table. I did comment out the line as I was trying different things.  I didn't notice I had left the comment slashes in. Below is the full code with the same error: // Handle the placement of new cards on("ready",function(){     // Trigger on deletion of a graphic     on('destroy:graphic',handleGraphicDestruction); }); // ----- var handleGraphicDestruction = function(obj,prevObj) {     // Log it     log(['Destroy',obj]);     // make sure it's a card     if(obj.get('_subtype')=='card')     {         var theCardID = obj.get('_cardid');         obj.set('imgsrc',getCleanImgsrc(obj.get('imgsrc')));         playCardToTable(theCardID,{left: 100, top: 100});     } } // added in attempt to avoid an error when placing card var getCleanImgsrc = function (imgsrc) {    var parts = imgsrc.match(/(.*\/images\/.*)(thumb|max)(.*)$/);    if(parts)   {       return parts[1]+'thumb'+parts[3];   }   return; };
1592313984
The Aaron
Roll20 Production Team
API Scripter
Use this version of getCleanImgsrc, that one is missing a few cases: const getCleanImgsrc = (imgsrc) => { let parts = imgsrc.match(/(.*\/images\/.*)(thumb|med|original|max)([^?]*)(\?[^?]+)?$/); if(parts) { return parts[1]+'thumb'+parts[3]+(parts[4]?parts[4]:`?${Math.round(Math.random()*9999999)}`); } return; }; The issue is that the API can only create images that use the thumb sizing.  The UI will happily create other sizes (usually med or max), so if you're recreating a graphic created by a player, it might have a size the API can't create.  This version of the function should deal with that. Note also that the API can only create images in a User Library, so if it's from the Marketplace, it won't be able to create it.  This function will return undefined for such images, so you can check it after calling.
1592314948
The Aaron
Roll20 Production Team
API Scripter
Also, sides is not just an image, it's a urlencoded collection of image urls separated by pipe characters.  While you could run getCleanImgsrc() on the urls in sides, you'd need to split it on pipe and decode it first, then re-encode it and join it back to a string to set.
1592315185
The Aaron
Roll20 Production Team
API Scripter
Also, you shouldn't change the object in the delete handler, as the object is being removed, so any changes will get removed with it.  If playing a card to the table isn't working, you can try deferring it until after the delete finishes:  setTimeout(()=>playCardToTable(theCardID,{left: 100, top: 100}),0); Also, playCardToTable() might have a bug.  I seem to remember reporting one a while back...
1592315373
The Aaron
Roll20 Production Team
API Scripter
Ah yeah.. seems there is an issue:&nbsp; <a href="https://app.roll20.net/forum/post/8423978/manipulating-multiple-cards-or-decks-at-once" rel="nofollow">https://app.roll20.net/forum/post/8423978/manipulating-multiple-cards-or-decks-at-once</a>