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

[Help] Add 0.1 to custom entry on turn order tracker...

I just want to add 0.1 to the current initiative value of a custom entry in the turn order tracker. I'll add if/else statements later to add to a specific named entry. That part is easy. What I'm having trouble with is setting CurrentRound on the turn object and getting that back into the turn order. on("change:campaign:turnorder", function(obj, prev) { if (!Campaign().get("turnorder")) return; var turn_order = JSON.parse(Campaign().get("turnorder")); if (!turn_order.length) return; var turn = turn_order.shift(); if (turn.id == -1) { var CurrentRound = parseInt(turn.pr); CurrentRound = CurrentRound + 0.1; ???? return; } });
I think this would do it if I'm understanding your question correctly. So basically it checks to see if the current thing at the top of the turn list has an id of -1 (meaning it's a custom item -- so this assumes you only have one custom item and it is your round counter), if so it adds 0.1 to the current value of the turn item, and then saves those changes back to the Campaign object. Note that I changed "parseInt" to "parseFloat" since you are using decimals in your values. (Note: Untested, may have typos/bugs) on("change:campaign:turnorder", function(obj, prev) { if (!Campaign().get("turnorder")) return; var turn_order = JSON.parse(Campaign().get("turnorder")); if (!turn_order.length) return; if (turn_order[0].id == -1) { //check to see if the first thing on the list is a custom item var CurrentRound = parseFloat(turn_order[0].pr); //get the current value CurrentRound = CurrentRound + 0.1; //add 0.1 turn_order[0].pr = CurrentRound; //set the new value back as the value for this item Campaign().set({turnorder: JSON.stringify(turn_order)}); //save the changes back to the Campaign object return; } });
Hrm, totally did not work, but did point me in the right direction I think. It deleted the custom turn order tracker entry and added 0.1 to the next object on the list.
It did? Hm. Well I'm not at a computer to actually test it right now. That's what I would have expected it to do with the shift() function that was there previously, but not sure why it's doing that now.
Ah ok, I see what you did. You re-wrote some of the stuff I had written. There's more to the script than just that and I only copied the part about adding 0.1 to the Round custom item. It works now... but I don't like the 0.1 for aestehtic reasons. I'll just have to change the name of the custom item.