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
This post has been closed. You can still view previous posts, but you can't post any new replies.

[HELP] Why is setAttrs not running?

1457993786
James
Sheet Author
I have the following sheetworker: on("change:repeating_college remove:repeating_college", function() { getSectionIDs("repeating_college", function(idArray) { if(idArray.length == 0) { console.log("ID Array is blank"); console.log(idArray); setAttrs({"ismage":0}); } else { console.log(idArray); var concat = ""; var counter = 0; for (var i=0; i < idArray.length; i++) { var idname = idArray[i]; console.log(idname); console.log("attrname: " + "repeating_college_" + idname + "_college"); getAttrs(["repeating_college_" + idname + "_college"], function(objCollege) { console.log(objCollege); var collegeName = objCollege[Object.keys(objCollege)[0]]; console.log(collegeName); if(collegeName == undefined) { collegeName = ""; console.log(collegeName); } concat += collegeName; console.log("concat: " + concat); counter ++; console.log("counter: " + counter); }); } var check = function(a, b) { if (a!=b) { setTimeout(check, 50); console.log("WAITING!"); return; } console.log("concat is now: " + concat); if (concat == "") { console.log("All entries are empty"); setAttrs({"ismage":0}); } else { console.log("Colleges are non-empty"); console.log("non empty concat:" + concat); setAttrs({"ismage":1}); } }; check(counter, idArray.length); } }); }); Everything works fine except my attempt to set attributes with setAttrs. I get an error in the console log: sheetsandboxworker.js?20150218:118 Character Sheet Error: Trying to do getAttrs when no character is active in sandbox. I know it says getAttrs - this is a bug with Roll20 (I've logged it). When I look at line 118 it is in the function setAttrs(). Can anyone explain why?  Thanks!
1458059927
Phil B.
Forum Champion
Sheet Author
Can you create a  Gist for me with all of the HTML and CSS for the sheet, so I can test this out.
1458087088
James
Sheet Author
Hey Phil, I hope that  this Gist is set up ok! Thanks.
1458098678

Edited 1458098690
chris b.
Pro
Sheet Author
API Scripter
I have received that message 1 of 2 times is the repeating item in question outlined in red, or when you inspect it do you see it wrapped in the class repitembroken that particular item has to be deleted and added again. or when my javascript was calling functions on non existent rows with invalid IDs., which can happen if events are fired in a certain way but I don't see that in your code. This happened to me in exactly the same circumstance: I had an on("change:repeating_section") and then used getSectionIDs to make adjustements on all sections.  The way I worked around it was to remove the generic change at the "top" of the repeating section and replace it looking for changes to exact fields in the section. So since your field looks like "college", change yours to on("change:repeating_college:college remove:repeating_college",function(..){}); you might find your error goes away. 
1458147622
Phil B.
Forum Champion
Sheet Author
I am also seeing this issue on that sheet. It looks like for some reason the "activeCharacterId" is not being set on the back end, so when it tries to setAttrs it doesn't have a target. I'm looking into it.
1458150258
Phil B.
Forum Champion
Sheet Author
It is because you are using setTimeout to wait for things to happen. When a sheetworker notification message is sent the "activeCharacterId" is set, and as soon as the message is done sending is follows up by removing the "activeCharacterId". So, when you run your setAttr through setTimeout, it is then run asynchronously and the message is then considered "complete" and the activeCharacterId is removed before you get around to calling setAttr again. Instead of running the getAttrs inside of the for loop, just use the for loop to compile an array of all of the attrs you want then call one single getAttrs(allTheAttrs, function(colleges) { _.each(colleges, function(value, key) { do stuff; }); saveAttrs(updates);});
1458174897
James
Sheet Author
Thanks, Chris & Phil. It looks like I need to improve my coding technique; I am an amateur (in both senses of the word).
1458233727
Phil B.
Forum Champion
Sheet Author
Np James, I always like helping with script stuff. Since we've figured out what the issue was, I'm going to go ahead and Resolve and Close this thread. If you run into any more problems you can always feel free to open a new thread and we'll help you out there. Happy Scripting!