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

5e Shaped Companion Script

1648029007

Edited 1648029298
Hello awesome community! I'm no expert on Javascript and need some insights. BTW I'm the player helping troubleshoot the error. DM is Pro user so we have API access. We use the 5e Shaped sheet for our game (I know it is not longer supported). Recently the API is no longer working with error&nbsp; " Possible infinite loop detected, shutting down. ". The error only occur when the companion script is enabled. After more digging I think something wrong with this part (I may be wrong. Again no expert here): roll20.on("ready", function() { logger.info("-=&gt; ShapedScript " + SCRIPT_VERSION + " &lt;=-"); logger.info("-=&gt; debug 1 &lt;=-"); var character = roll20.createObj("character", { name: "SHAPED_VERSION_TESTER" }), campaignSize = roll20.findObjs({}).length; logger.info("-=&gt; debug 2 &lt;=-"); logger.debug("Campaign size: $$$", campaignSize), roll20.createAttrWithWorker(character.id, "sheet_opened", 1, function() { runStartup(character, 0) }) }) I added those logger.info so I can better track what's going on. The script successfully create the "SHAPED_VERSION_TESTER" character sheet and add "sheet_opened" to Attributes. However, I don't think it fires the "runStartup" function at all. I tried the logger.info before "runStartup" and the first line in the actual function, but nothing return in the console. More info: we use the 5e Shaped sheet in the One Click install and the script from here:&nbsp; <a href="https://github.com/mlenser/roll20-api-scripts/tree/master/5eShapedScript" rel="nofollow">https://github.com/mlenser/roll20-api-scripts/tree/master/5eShapedScript</a> . I also tried create a new campaign with the same setup and it works perfectly. The only difference is the size of the campaign. Really appreciate it if anyone can share some light on how to fix it!
1648055857
The Aaron
Roll20 Production Team
API Scripter
Hmm.&nbsp; Try replacing this line: runStartup(character, 0) with this line: setTimeout(()=&gt;runStartup(character, 0),0); If that doesn't work, we'll need to dig into the runStartup function and see how we can split it up to be asynchronous. The Possible Infinite Loop Detected error happens when a script is doing too much work before returning to the sandbox.&nbsp; Basically, the sandbox starts a stopwatch when it calls into a script.&nbsp; If the stopwatch gets to a particular time (60s I think?), it considers it to be a runaway script and kills the sandbox.&nbsp; You fix that by returning control to the sandbox periodically, usually by scheduling more work in a callback function.&nbsp; The above creates an anonymous function ()=&gt; which calls the original line, then passes it to setTimeout( ..., 0), to schedule it after the current call stack has returned.&nbsp; That allows the stopwatch to be reset before the line is executed.
Thank you for the suggestion Aaron! Unfortunately that doesn't work. Here is the code: roll20.on("ready", function() { logger.info("-=&gt; ShapedScript " + SCRIPT_VERSION + " &lt;=-"); logger.info("-=&gt; ShapedScript debug 1 &lt;=-"); var character = roll20.createObj("character", { name: "SHAPED_VERSION_TESTER" }), campaignSize = roll20.findObjs({}).length; logger.info("-=&gt; ShapedScript debug 2 &lt;=-"); logger.debug("Campaign size: $$$", campaignSize), roll20.createAttrWithWorker(character.id, "sheet_opened", 1, function() { setTimeout(()=&gt;runStartup(character, 0),0); //runStartup(character, 0) }) }), function runStartup(character, retryCount) { var version = roll20.getAttrByName(character.id, "version", "current", !0); !version &amp;&amp; retryCount &gt; 0 &amp;&amp; (version = searchSheetsForVersion()); var ed = new EventDispatcher(roll20, errorHandler, logger, reporter), cw = new ChatWatcher(roll20, logger, ed), commandProc = makeCommandProc("shaped", roll20, errorHandler, ed, version, logger); if (!version) { if (retryCount &gt; 4) { var error = "Couldn’t find Shaped Character Sheet. This Shaped Script requires the Shaped Character Sheet to be installed in the campaign."; return roll20.sendChat("Shaped Companion Script", error, null, { noarchive: !0 }), logger.error(error), commandProc.setDefaultCommandHandler(function() { return reporter.reportError(error) }), void _.invoke(roll20.findObjs({ type: "character", name: "SHAPED_VERSION_TESTER" }), "remove") } return logger.debug("No version attribute found yet, delaying for another 4 seconds. Retry count " + retryCount), void _.delay(runStartup.bind(null, character, retryCount += 1), 4e3) } var sheetAPIVersion = roll20.getAttrByName(character.id, "script_compatibility_version"); if (logger.info("Detected sheet version as : $$$", version), Utils.versionCompare(version, MINIMUM_SHEET_VERSION) &lt; 0) { var _error = "The Shaped Script requires the Shaped sheet to be version " + MINIMUM_SHEET_VERSION + " or higher. You're currently using version " + version + ". Please install the latest Shaped sheet from github: <a href="https://github.com/mlenser/roll20-character-sheets/tree/master/5eShaped" rel="nofollow">https://github.com/mlenser/roll20-character-sheets/tree/master/5eShaped</a>"; return reporter.reportError(_error), logger.error(_error), void commandProc.setDefaultCommandHandler(function() { return reporter.reportError(_error) }) } if (SHEET_API_VERSION !== sheetAPIVersion) { var _error2 = "WARNING: Character sheet has been updated with breaking changes that this version of the Script does not yet support. Some features may not work as expected. Please check for an updated version of the script."; reporter.reportError(_error2), logger.error(_error2) } var sc = new ShapedConfig({ roll20: roll20, reporter: reporter, logger: logger, myState: myState }); sc.configure(commandProc, cw, ed), sc.runStartupSequence(commandProc, function() { commandProc.setDefaultCommandHandler(function(cmd) { return reporter.reportError("Unknown command " + cmd) }), moduleList.forEach(function(module) { return module.configure(commandProc, cw, ed) }), _.invoke(roll20.findObjs({ type: "character", name: "SHAPED_VERSION_TESTER" }), "remove"), entityLookup.listenForEntityLoadFinish(function(entities) { var contentGroups = "&lt;ul&gt;&lt;li&gt;" + entities.join("&lt;/li&gt;&lt;li&gt;") + "&lt;/li&gt;&lt;/ul&gt;"; reporter.reportPlayer("Shaped Script Ready", "Script Version: " + SCRIPT_VERSION + "&lt;br&gt;Sheet Version: " + version + "&lt;br&gt;Content Groups Loaded:" + contentGroups) }) }) }
1648067577

Edited 1648067594
And the error message:
1648077348

Edited 1648077656
Oosh
Sheet Author
API Scripter
God, I hate Webpack. So, this looks fishy, line 19016: &nbsp; &nbsp; onSheetWorkerCompleted ( cb ) { &nbsp; &nbsp; &nbsp; onSheetWorkerCompleted ( cb ) &nbsp; &nbsp; } I'm assuming that should have a 'return' in there, like all the other packed functions around it? Not sure. You could try changing the createAttrWithWorker function just below it (line 19025) with the following: &nbsp; &nbsp; createAttrWithWorker ( characterId , attrName , attrValue , cb ) { &nbsp; &nbsp; &nbsp; const attr = this . createObj ( "attribute" , { &nbsp; &nbsp; &nbsp; &nbsp; characterid : characterId , &nbsp; &nbsp; &nbsp; &nbsp; name : attrName &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; attr . setWithWorker ({ &nbsp; &nbsp; &nbsp; &nbsp; current : attrValue &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; cb (); &nbsp; &nbsp; } I'm not quite understanding what the original is doing, but webpacked functions hurt my brain a bit. It didn't appear to be actually invoking the callback, but I could be totally wrong about that. Anyway, see if that at least gets runStartup to log a line. If it's currently not logging even the first line, I'm thinking that callback is where the issue is - the 4th argument supplied to createAttrWithWorker. Edit - actually, I just noticed there's no logging before the runStartup call. Try chucking a log in there first, very first line of the callback before runStartup is called.
Thank you Oosh! I added another logger: roll20.on("ready", function() { logger.info("-=&gt; ShapedScript " + SCRIPT_VERSION + " &lt;=-"); logger.info("-=&gt; ShapedScript debug 1 &lt;=-"); var character = roll20.createObj("character", { name: "SHAPED_VERSION_TESTER" }), campaignSize = roll20.findObjs({}).length; logger.info("-=&gt; ShapedScript debug 2 &lt;=-"); logger.debug("Campaign size: $$$", campaignSize), roll20.createAttrWithWorker(character.id, "sheet_opened", 1, function() { logger.info("-=&gt; ShapedScript debug 3 &lt;=-"); setTimeout(()=&gt;runStartup(character, 0),0); //runStartup(character, 0) }) }), Without your suggested change, the "debug 3" never show in the console. However, with your change there is another error (I don't think it's related to the runStartup anymore):