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

t.get not a function? Where am I going wrong?

Hey, hopefully this issue isn't too blindingly obvious and I'm not being silly but I was banging my head away trying to solve this yesterday and didn't really get a satisfying fix and it's just broken the update I wanted to push to CorpseCart  (as I broke the ability to remove tokens from the map layer with the release version). My current issue is this function: //FIND CORPSES TO DEL OR MAP function findCorpses(mapID,corpseCom){ var corpseTokensAll = findObjs({ _type:"graphic", _subtype: "token", status_dead : true, layer: "objects", _pageid: mapID, }); if (corpseCom==comDel){ let corpseTokensAllMap = findObjs({ _type:"graphic", _subtype: "token", status_dead : true, layer: "map", _pageid: mapID, }); log(typeof corpseTokensAllMap); corpseTokensAll.push(corpseTokensAllMap); log(typeof corpseTokensAll); } log("Stage FC1"); corpseTokensAll = corpseTokensAll.filter(t => t.get('represents') !== ""); log("Stage FC2"); var corpsetokens = corpseTokensAll.filter(t => getObj('character',t.get('represents')).get('controlledby') == ""); log("Stage FC3"); if (corpsetokens===undefined || corpsetokens.length == 0){ sendChat("Corpse Cart", "/w gm No corpses found to cart.",null,{noarchive:true}) return; } else{ log("Number of Corpses to Cart: "+corpsetokens.length); corpseCom == comDel ? corpsetokens.forEach(deleteCorpses) : false; corpseCom == comMap ? corpsetokens.forEach(buryCorpses) : false; sendChat("Corpse Cart", "/w gm Carted away " + corpsetokens.length + " corpses.",null,{noarchive:true}) } log("Stage FC4"); } What this does is grabs all tokens with the dead marker on the object layer, adds those on the map layer if the command (corpseCom) was to delete them (comDel) and then filter for NPCs before sending to the move to map or deletion functions. Issue is that only  and only for deletion it is throwing the error every time of: TypeError: t.get is not a function at apiscript.js:28781:71 at Array.filter (<anonymous>) at findCorpses (apiscript.js:28781:38) at apiscript.js:28720:6 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:168:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1739:12 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) My log shows that Stage FC1 and then the error being thrown, so it's definitely t.get("represents") causing an issue, and apparently only of something on the map layer, as object layer runs fine. On blank maps it goes ok, and this is a map that is deliberately filled with half built and malformed/disconnect tokens and graphics to check for real use conditions. I'm at a loss for what it is and why I cannot just filter it out, doesn't every subtype:token  have a represents field that I should be able to filter via? Sorry if my understanding and particularly jargon is limited, my background is not coding or backend work at all!
A guess: corpseTokensAll.push(corpseTokensAllMap); corpseTokensAllMap is an array. You are then adding that array to your existing corpseTokensAll array. When you run filter() on corpseTokensAll, it tries to run get() on each element; one of those elements is corpseTokensAllMap, which is an array and has no get(), so the error is thrown. If you were instead looking to combine corpseTokenAll and corpseTokenAllMap into one flat array of Roll20 objects you want to use something like: corpseTokenAll = corpseTokenAll.concat(corpseTokensAllMap); Jim
Jim R. said: A guess That was it, you're a lifesaver! I'm definitely not used to this whole weird array/object/class system yet, what a silly mistake.
1652710594
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I make that sort of mistake ALL the time. Over and over, because I never learn. :)