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

Unexpected token _ error

I have an error called "unexpected token_" It is occurring in my API console. Even if I disable all but one of my scripts the error is still there. Has anyone else encountered this? I am not quite sure what to do...
1384338445

Edited 1384343545
I have now backed up my campaign again and transferred all the scripts across. It is an exact replica but it is working. I must have broken something on my original campaign but I cannot figure out what it is. Any ideas? I would like to know what I have done so it does not happen again.
"Unexpected token" is a Javascript error that means there is a syntax error somewhere in your script. I'm not sure why it wouldn't still be there if you copied the scripts exactly. Maybe a copy/paste issue that got cleaned up?
Everything was working perfectly yesterday... I now keep getting "Infinite loop or long running process detected" when using my scripts on my campaign copy. It's not a syntax error in one of the scripts because if I disable all of the scripts on my original campaign and enable any single script it will return the error.
Hmmm...well I got a "Infinite loop" error just now as I was preparing my campaign for tonight on Dev, but that was caused by the Dev Server account refresh thing (I tried to save a script right as that happened). And re-saving my script cleared it up....
No such luck for me... Something weird has happened to my campaign. it's like the tokens have all gone out of sync. My scripts are not updating the tokens health etc... The scripts are reporting the correct numbers when I log the data but it is not transferring to the tokens. It's like the tokens have become corrupted?
1384379115

Edited 1384379228
Riley can you please check something? I swear that something has changed and this is why my scripts have gone haywire. bonus.set("bar1_value", HP); (this has been working for two weeks within this function) It is no longer changing the value of bar1 for the relevant token/character.
Is this on the Main server or Dev server? I pushed some new code out to Dev for the API stuff that's incoming Friday, but I don't think it should have affected anything that basic. Of course, famous last words.
1384379761

Edited 1384380015
Dev Server... And i swear something has messed with it. I changed nothing and now it will not change my tokens values. I have even created a new campaign and tested it. Same result. It will read the tokens values fine but it will not change them. When I log the data in the console it is showing the correct values and the ID for the token is correct, it is even tracking the change in value for the token in the API but not updating the token in roll20. If I have made an error then I apologise for the trouble but just to let you know this first occurred approx 12 hours ago. When did you do the update?
1384379908

Edited 1384379930
Riley D.
Roll20 Team
Actually I was mistaken, it looks like I broke it on Dev for bar values that were linked to Characters. Should be fixed now. Still no idea why you'd have on that's stuck on "Infinite loop" though.
Thanks! Thought I was going mad :)
Callum M. said: Thanks! Thought I was going mad :) No problem, sorry for the confusion :-)
That sorted the token error. Now I keep getting 'Infinite loop or long running process detected.' when I use my spellcasting script (this was also working without any issues yesterday)
Found it.... var targetMatched = findObjs({ name: targetName, _type: "graphic", }); _.each(targetMatched, function(obj) { var Bonus = findObjs({ _type: "graphic", _id: obj.id, }); _.each(Bonus, function(bonus) { targetID = bonus.get("_represents", holder); HP = parseInt(bonus.get("bar1_value", holder)); // HP of target log(targetID); }); }) Yesterday this was working fine, today it is no longer grabbing the ID of the token.
Riley, I am starting to realise that there are issues with nearly all of my scripts since the recent update to the Dev server. My equipment script is also not operating properly.
interesting... I had to take out the underscore in the reference to "_represents". Working now!
Yeesh, sorry about that. Things are sort-of in a "half-changed" state right now. I just pushed a quick shim that will allow get() to work with properties that are going to be changing to read/write but were previously read-only. So basically you can do "_represents" or "represents" now, even though it's actually "represents" since it's no longer read-only. Sorry again for the trouble.
This is killing me. I now have an error: "Unexpected string" It has destroyed my API scripts again. None of them are working. I disable all of them and I still get this error. All of these problems began last night. There is no way that I can recover my campaign when these errors happen. I have to copy the campaign and then transfer all of the scripts across to the new copy... It will then work for about an hour before popping up "Unexpected token" or "Unexpected String".
Here is some more info for you Riley: If I delete all of my scripts and then start a new script the error is still present. So the API has somehow corrupted my campaign and created a permanent error that I cannot fix. The only way around it is for me to copy my campaign and transfer all my scripts across. I have already done this twice.
Well I didn't push any changes out until around noon today. So if it started happening last night, it may not be related to that. Do you know what part of the script is causing the "Unexpected string" error? As in, is it happening in response to an event being called? Or it just happens whenever you load the script at all?
I really have no idea... I am trying to nut it out. It's probably just my dodgy code. It was fine for the last week, that is what has me stumped.
I mean, if you post the code you're having problems with and a test case that can reproduce it (e.g. game setup) I'm more than happy to take a look at it.
actually, my game is having similar problems - I haven't been able to get the api running for a few days now. even with all the api scripts set to disabled it just comes up complaining about long running processes.
I mean the error won't clear if you don't Save an active script to restart the sandbox. Try having just a simple script that just does like: on("ready", function() { log("Hello!"); }); And just have that one enabled. See if that does anything.
I followed your instructions. Created a new script with all of the other scripts disabled. It returns this error: 'Unexpected end of input' I am in the process of making my scripts more robust by doing some proper error handling to avoid this. I don't know much about programming but I have certainly found a way to break the API console :)
Are you sure you have all the other scripts disabled? And you pasted in the whole script? 'Unexpected end of input' usually indicates a missing semicolon or something like that. I just copy+pasted that script into an API Script on a Campaign that doesn't have any others and it seems to work fine. What campaign is it that you're doing this on?
This one: <a href="https://app.roll20dev.net/campaigns/details/29909/pathfinder-using-forgotten-realms-campaign-setting-second-backup" rel="nofollow">https://app.roll20dev.net/campaigns/details/29909/pathfinder-using-forgotten-realms-campaign-setting-second-backup</a> Please check it out and let me know what you think. Link to the API for the campaign: <a href="https://app.roll20dev.net/campaigns/scripts/29909" rel="nofollow">https://app.roll20dev.net/campaigns/scripts/29909</a>
It just happened again on another copy... <a href="https://app.roll20dev.net/campaigns/details/29929/pathfinder-using-the-forgotten-realms-campaign-setting" rel="nofollow">https://app.roll20dev.net/campaigns/details/29929/pathfinder-using-the-forgotten-realms-campaign-setting</a> API: <a href="https://app.roll20dev.net/campaigns/scripts/29929" rel="nofollow">https://app.roll20dev.net/campaigns/scripts/29929</a> Cannot be recovered.
Not sure that this is related to your issues at all, but I've found that if I accidentally save a script with no name it ends up in a nearly invisible tab. Since I can't see the script I can't easily disable it. Are you making any changes in these campaigns before they break?
Okay, I'm taking a look now. I'll figure it out.
1384527265

Edited 1384536455
Riley D.
Roll20 Team
Okay, so apparently your "state" object (the one that is persisted between sessions) had somehow become corrupt. I just added some code that can handle that more gracefully, resetting the state back to an empty object if that happens. In the last campaign you linked (29929) I disabled all your other scripts and ran the test script and it works fine now. But your previous copies should also work now. However I would look through your scripts and make sure there isn't anything that could leave your state object in a broken state. Or just do some experimenting and pay attention to what's happening before you get the "State object was corrupt" log message. Or if the state object isn't really something you care that much about saving between sessions, then you can just ignore that message and carry on, it only matters if you're trying to "save" API state data between gaming sessions.
Thank you for all of your help Riley. The previous copies still don't work (but that does not bother me as long as the problem does not arise again). I will keep you posted.
John M. said: Not sure that this is related to your issues at all, but I've found that if I accidentally save a script with no name it ends up in a nearly invisible tab. Since I can't see the script I can't easily disable it. Are you making any changes in these campaigns before they break? No changes to the campaign but I am using various attack macros and spell buff macros to test the script. The problem is occurring when I make multiple changes to the state object in a short space of time.
Callum M. said: John M. said: Not sure that this is related to your issues at all, but I've found that if I accidentally save a script with no name it ends up in a nearly invisible tab. Since I can't see the script I can't easily disable it. Are you making any changes in these campaigns before they break? No changes to the campaign but I am using various attack macros and spell buff macros to test the script. The problem is occurring when I make multiple changes to the state object in a short space of time. How short?
If I have say 5 buffs on a target (which are stored in the state object) and then try and run a loop that is removing all of these buffs then I constantly get the message "infinite loop or long running process detected". It will remove up to two at once but anymore than that and I always receive the error message. On the rare occasion it will corrupt the state object. Here is the code that receives the chat message to delete all of the data stored in the object: on("chat:message", function(msg) { var cmd = "!StatusDelAll"; if (msg.type == "api" && msg.content.indexOf(cmd) !== -1) { //&& msg.who.indexOf("(GM)" !== -1)) { var CharID = ""; var Duration = 0; var statusName = ""; var loop = 0; var maxLoops = state.activeStatus.length; var cleanedMsg = msg.content.replace(cmd, ""); while (loop &lt; maxLoops) { _.each(msg.selected, (function (obj){ //Pulls the selected ID token = getObj("graphic", obj._id); if (token.get("represents") == "") { CharID = token._id; } else { CharID = token.get("represents"); } if (obj._type == "graphic" && state.activeStatus[loop].CharID == CharID) { //only if the selected is a token StatusTracker.DelStatus(state.activeStatus[loop].CharID, state.activeStatus[loop].statusName, state.activeStatus[loop].Duration); //drop loop by 1 now that there is 1 less object in the array. loop = loop - 1; maxLoops = state.activeStatus.length; } })) loop = loop + 1; } } }); Here is the DelStatus function: StatusTracker.DelStatus = function(CharID, statusName, Duration){ var name = ""; var holder = ""; var loop = 0; var maxLoops = state.activeStatus.length; while (loop &lt; maxLoops) { if (state.activeStatus[loop].statusName == statusName && state.activeStatus[loop].CharID == CharID) { var getName = findObjs({ _represents: CharID, _type: "graphic", }) _.each(getName, function(getname) { name = getname.get("name", holder); }) //StatusTracker.updateStatsPenalty(CharID, statusName) message = '&lt;b style="color:red;"&gt;' + "'" +state.activeStatus[loop].statusName + "'" + '&lt;/b&gt;' + " ends for " + name; StatusTracker.sendMessage(message, state.activeStatus.GMOnly, state.activeStatus[loop].statusDescript); var Value = state.activeStatus[loop].Value //Remove the relevant marker StatusTracker.delMarker(state.activeStatus[loop].CharID, state.activeStatus[loop].Marker); StatusTracker.updateStatsPenalty(CharID, statusName, Duration, Value) state.activeStatus.splice(loop,1); return; } loop = loop + 1; } } The 'updateStatsPenalty' function updates the characters attributes based on the spell buff that was just removed. (Too much code to post in here) If I try and remove more than 2 spell buffs at once then I receive the error message.
While this doesn't address the underlying issue of corrupted state , have you considered implementing activeStatus as an object instead of an array? You could then index the status by CharID and not have to loop through the whole mess looking for your matching IDs.
John M. said: While this doesn't address the underlying issue of corrupted state , have you considered implementing activeStatus as an object instead of an array? You could then index the status by CharID and not have to loop through the whole mess looking for your matching IDs. I have and I probably will. Thank you for the suggestion. I have a suspicion that it will likely fix the issue that I am having. I am very new to javascript (the last time I did any programming was 20 years ago when I was 16 years old using 'BASIC'). I have been stealing other scripts from the forum and modifying them and learning in the process.