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

Unable to Access Campaign() Object

I'm attempting to make a helper function which sets the turn order, but I'm falling at the first hurdle! Even though I'm using exactly the code provided by Roll20's Help docs,  I'm getting an error when attempting to even get the turn order object: function setTurnOrder(value) {     var turnorder;     if (Campaign().get("turnorder") == "") turnorder = [];     else turnorder = JSON.parse(Campaign().get("turnorder")); }; [Log] ReferenceError: Can't find variable: Campaign (sheetsandbox.bundle.js, line 3339) setTurnOrder (anonymous function) (anonymous function) — sheetsandboxworker.js:149 messageHandler — sheetsandboxworker.js:768 Any permutation of 'Campaign()' gives the same error - it's not being found, but I don't know why. Is it because the Campaign object's not accessible in some situations? Is it because I'm running the code in the Custom Sheet Sandbox and the Campaign object doesn't exist there? Please help!
1732310166

Edited 1732314953
It seems like maybe this will only work within a Mod, rather than a custom character sheet. Is that right? I'm not familiar with Mods and their creation, so, on reflection, this likely isn't the right category for this post.
1732320516
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yes, that is only available in the server side mods. Sheets can't do anything with the tracker other than add entities to it via the chat syntax.
Thanks for confirming. Shame to hear there’s not really a way to do this programmatically in custom sheets. I’ll use a chat roll as a workaround, but it’s a shame to generate that additional noise in the chat window.
1732385301
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
If it doesn't need to be seen by the user, send it as an API command. That will hide it from chat and still do everything necessary. To send as an API command, just prepend with an exclamation point.
That's a great tip. Thank you! I didn't know that was an option; but it works perfectly.