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!!!] I've got a bug that cropped up and I just can't find it...

1369542759
Konrad J.
Pro
API Scripter
This might be something for Riley.  I've been debugging for hours, not sure how to even explain the problem, but here it goes. My script is fairly large at the moment, its a bunch of my scripts all put together. I get this error... undefined:88 var currentState = JSON.stringify(exports.api.state); ^ TypeError: Converting circular structure to JSON at Object.stringify (native) at Timer.eval ( Its happening within a setInterval.  But the funny thing is during the very start of the script in a On(ready event I call a function.  Within this function I save my global variables to the state, state.fwGlobal = fwGlobal.  The setInterval has nothing to do with the on(ready event or the saving of the global variables.  If I comment out the one line state.fwGlobal = fwGlobal the setInterval script runs fine and the timer runs.  If I leave it in then the time ticks once and crashes with that error.  But the state save has long been saved before I even initiate the timer script with a chat window command. Its really bogged me down, wasted many hours troubleshooting. :)  I can post the code or the campaign if it will help, but its fairly involved script so it might be hard to follow everything right away for someone looking at it for the first time. :) I'm hoping for some ideas.  I think I'll put the scripting down for tonight and pick it up again another day.  Too much debugging is no fun! :) Thanks for your help.
As the error says, you are probably creating a circular reference. That means for example you are doing: obj2 = {hello: "konrad"} obj1 = {"how are": "you"} obj2.ref = obj1 obj1.ref = obj2 Now when you try to stringify object 1 it sees obj1.ref = obj2, so it follows that to obj2, then it tries to stringify obj2, and it sees obj2.ref = obj1, so it goes to obj1, and now you have a circular reference that will never end. It is trying to save the current global state object, and in doing so it is encountering the circular reference. Double-check and make sure that there isn'ta  reference to the global state object in your fwGlobal object.
1369699709
Konrad J.
Pro
API Scripter
Thanks again for trying to help! I had a look at fwGlobal and no reference to state inside of that object. :) The state save actually works just fine.  And its only happening during the beginning in an on(ready event.  If later I run the timer part of the script it crashes.  But if I only save the one variable I need to save instead of the whole thing then the timer part of the script runs no problem.  Also I'm not doing Stringify anywhere in my script.  It will end up being something silly I know, it always is.  I'll keep looking.  THanks again for some ideas. //state.fwGlobal = fwGlobal;  // this causes the timer to crash??? no idea why yet state.fwGlobal.moveInfoTextTmp = fwGlobal.moveInfoTextTmp;
Try doing log(fwGlobal) and see what happens.
1369701655
Konrad J.
Pro
API Scripter
No problems doing that.  I did a log on both fwGlobal and state.fwGlobal.  No problems.  I get the same info like it should come up as at that point. {"rotationEnable":false,"moveEnable":true,"sizeEnable":false,"GMName":"Konrad J.","timeStampLog":false,"timeStampDiceLog":false,"timeStampOutput":false,"timeStampChatOutput":false,"tClockName":"fw.clock.timer","tST":0,"tSI":0,"tClockDirection":"up","tClockOn":false,"tClockRotate":false,"tClockStatusMarker":false,"tClockLogChat":false,"tClockAura":false,"tClockTint":false,"tRestarted":false,"tRestartedTimer":0,"moveInfoTextEnable":false,"moveInfoTextTmp":"fw.move.info.text","moveInfoText":"fw.move.info.text","moveInfoTextBackgroundName":"fw.move.text.background","movementMarkerAuraName":"fw.move.marker.aura","movementMarkerLastMoveName":"fw.move.marker.last","trackEnable":false,"trackTokenName":"","unitsRemainingToMove":0} {"rotationEnable":false,"moveEnable":true,"sizeEnable":false,"GMName":"Konrad J.","timeStampLog":false,"timeStampDiceLog":false,"timeStampOutput":false,"timeStampChatOutput":false,"tClockName":"fw.clock.timer","tST":0,"tSI":0,"tClockDirection":"up","tClockOn":false,"tClockRotate":false,"tClockStatusMarker":false,"tClockLogChat":false,"tClockAura":false,"tClockTint":false,"tRestarted":false,"tRestartedTimer":0,"moveInfoTextEnable":false,"moveInfoTextTmp":"fw.move.info.text","moveInfoText":"fw.move.info.text","moveInfoTextBackgroundName":"fw.move.text.background","movementMarkerAuraName":"fw.move.marker.aura","movementMarkerLastMoveName":"fw.move.marker.last","trackEnable":false,"trackTokenName":"","unitsRemainingToMove":0}
Hmmm..yeah, I dunno. I mean, there's a circular reference somwhere. I guess I'd have to look at all of it to see... The JSON.stringify() part is happening "as part of the API", not anything you're doing, it's the part that saves the current state object automatically.
1369710101
Konrad J.
Pro
API Scripter
Riley D. said: Hmmm..yeah, I dunno. I mean, there's a circular reference somwhere. I guess I'd have to look at all of it to see... The JSON.stringify() part is happening "as part of the API", not anything you're doing, it's the part that saves the current state object automatically. I figured as much.  No worry.  I'll play around with it some more.  It works right now as long as I don't save the whole fwGlobal and then much later run the setInterval part of the script. :)  Thats a clue to the bug.  I'll dig deeper.