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

Is Retrieving Character Sheet from Turn Order Possible?

1387480716

Edited 1387480782
I'm currently trying to work a method of appending information to every character on an existing Turn Order. I've been unable to figure out a proper solution to it because to my current understanding the only retrievable information from the turn order is the graphics ID, the number input, the custom title should one exist, and the position (based on position in array). I've been searching high and low for some way to relate the Graphics ID back to the character sheets, but can't find the appropriate field when doing findObj. Any insight on the matter would be greatly appreciated. This is as far as I've gotten. And yes, I am exceedingly new to this, so please forgive the sloppy coding. on("chat:message", function(msg) { if (msg.type == "api" && msg.content.indexOf("!AddAPM") !== -1) { var turnorder; if(Campaign().get("turnorder") == "") turnorder = []; else turnorder = JSON.parse(Campaign().get("turnorder")); _.each(turnorder, function(obj) { var initAPM = findObjs({ name: "APM", _type: "attribute", id: obj.id, // This is the field I am having issues with. }); obj.pr = obj.pr + "(" + Math.ceil(initAPM.current/2) + "/" + Math.floor(initAPM.current/2) + ")" }) Campaign().set("turnorder", JSON.stringify(turnorder)); } })
You are looking for the "represents" property. Once you have the token id, you can get the id of the character's journal assigned to it like this: var oCharacter = getObj("character", obj.get("represents")); // this is the ID of the character journal assigned to this particular graphic object var oAttribute = findObjs({name: "whateveritsnameis",_type: "attribute", _characterid: oCharacter.id}, {caseInsensitive: true})[0]; // find the attribute var Attribute = oAttribute.get("current"); // get the value of the attribute Attribute.set("current", newvalue); // set a new (current) value for the attribute
1387560278

Edited 1387560302
Thank you very much! This helped immensely. I had to add one extra step in order for this to work, fetching the actual graphical object. Either way, this essentially was everything I needed. var obj2 = getObj("graphic", obj.id);
Michael A. said: Thank you very much! This helped immensely. I had to add one extra step in order for this to work, fetching the actual graphical object. Either way, this essentially was everything I needed. var obj2 = getObj("graphic", obj.id); Where did you add in this line? Thanks for idea!
1391252304
Chad
Sheet Author
Hi Michael, You might want to add a bit more code to avoid possible errors. Make sure something was actually returned when you use getObj... the reason for this is the "custom item" option in turn order... where a GM can put in anything they want. If your script expects getObj to return an object, and doesn't check to make sure one was actually returned, you may get runtime errors. Chad