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

Campaign won't load maps after API error

I attempted to create a text object with the API on the player page with the current time. After I ran the script, the campaign stopped loading maps. The current map disappeared (though fog of war is still working), and switching to other maps doesn't work either. Is there a way to fix this?
1411503936
Lithl
Pro
Sheet Author
API Scripter
What is the script?
It's a datetime script used to keep track of in-game time progression. I just added in the createObj code to create a text object that had the output information. Right now I just call the setTime function with the current date & time information. This, in turn, calls the showTime function. var current_year = 0; var current_month_index = 0; var current_date = 0; var max_days_in_month = 0; var current_day_index = 0; var current_time = "00:00:00"; var leap_year = true; var allMonths = ["January","February","March","April","May","June","July","August","September","October","November","December"]; var allMonthsDays = [31,28,31,30,31,30,31,31,30,31,30,31]; var allDays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; function populateData(months, monthDays, days){ allMonths = []; allMonthsDays = []; allDays = []; var index = 0; _.each(months, function(month){ allMonths.push(months[index]); allMonthsDays.push(monthDays[index]); index = index+1; }); _.each(days, function(day){ allDays.push(day); }); } function setTime(y, mo, d, h, mi, s){ current_year = y; current_month_index = mo; max_days_in_month = allMonthsDays[mo - 1]; current_date = d; current_time = zeroFill(h,2) + ":" + zeroFill(mi,2) + ":" + zeroFill(s,2); showTime(); var outputArray = getTime(); log("Year: " + outputArray[0]); log("Month: " + outputArray[1][0]); log("Date: " + outputArray[2][0]); log("Day: " + outputArray[2][1]); log("Time: " + outputArray[3][0]); } function getDayOfWeek(year, month, date){ var totalDaysInYear = 0; var daysThisYear = 0; var index = 0; _.each(allMonthsDays, function(days){ totalDaysInYear = totalDaysInYear + days; if(index <= (month - 2)){ daysThisYear = daysThisYear + days; } index = index + 1; }); daysThisYear = daysThisYear + date; var totalDaysInPast = ((current_year - 1) * totalDaysInYear) + Math.floor(current_year / 4); if(year % 4 == 0 && month > 1){ daysThisYear = daysThisYear + 1; } current_day_index = ((daysThisYear + totalDaysInPast) % allDays.length) + 1; while (current_day_index > 6) { current_day_index = current_day_index - 7; } return allDays[current_day_index]; } function progressTime(y, m, d, h, m, s, r){ current_year = current_year + y; current_month_index = current_month_index + m; current_date = current_date + d; var timevals = current_time.split(":"); var hours = parseInt(timevals[0]) + h; var mintues = parseInt(timevals[1]) + m; var seconds = parseInt(timevals[2]) + s; if(seconds > 60){ minutes = minutes + Math.floor(seconds / 60); seconds = seconds % 60; } if(minutes > 60){ hours = hours + Math.floor(minutes / 60); minutes = minutes % 60; } if(hours > 24){ current_date = current_date + Math.floor(hours / 24); hours = hours % 24; } if(current_date > max_days_in_month){ while(current_date > max_days_in_month){ current_date = current_date - max_days_in_month; current_month_index = current_month_index + 1; log("MonthLoop: " + current_month_index); if(current_month_index > allMonths.length){ current_month_index = current_month_index - allMonths.length; current_year = current_year + 1; } max_days_in_month = allMonthsDays[current_month_index - 1]; } } while(current_month_index > allMonths.length){ current_month_index = current_month_index - allMonths.length; current_year = current_year + 1; max_days_in_month = allMonthsDays[current_month_index - 1]; } if(current_date > max_days_in_month){ while(current_date > max_days_in_month){ current_date = current_date - max_days_in_month; current_month_index = current_month_index + 1; if(current_month_index > allMonths.length){ current_month_index = current_month_index - allMonths.length; current_year = current_year + 1; } max_days_in_month = allMonthsDays[current_month_index]; } } if(current_year % 4 == 0){allMonthsDays[1] = 29; } else { allMonthsDays[1] = 28; } current_time = zeroFill(hours) + ":" + zeroFill(minutes) + ":" + zeroFill(seconds); } function getTime(){ var outputTime = new Array(4); outputTime[0] = current_year outputTime[1] = new Array(3); outputTime[1][0] = current_month_index; outputTime[1][1] = allMonths[current_month_index - 1]; outputTime[1][2] = allMonthsDays[current_month_index - 1]; outputTime[2] = new Array(2); outputTime[2][0] = current_date; outputTime[2][1] = getDayOfWeek(current_year, current_month_index, current_date); outputTime[3] = new Array(4); outputTime[3][0] = current_time; outputTime[3][1] = parseInt(current_time.split(":")[0]); outputTime[3][2] = parseInt(current_time.split(":")[1]); outputTime[3][3] = parseInt(current_time.split(":")[2]); return outputTime; } function showTime() { var timeArray = getTime(); var obj = createObj("text", { pageid: Campaign().get("playerpageid"), top: 5, left: 25, width: 120, height: 30, text: timeArray[3][0] + " " + timeArray[2][1] + ", " + timeArray[2][0] + " " + timeArray[1][1] + " " + timeArray[0], font_size:14, color: "rgb(255,255,255)", layer: "Map & Background", }); log(obj); }
This thread also had a similar problem. <a href="https://app.roll20.net/forum/post/537824/bug-crea" rel="nofollow">https://app.roll20.net/forum/post/537824/bug-crea</a>... I managed to write a fix. I figured it was just an overpopulated list or some such that was causing the problem. Effectively, the text object was added to a layer that didn't exist. This code fixed the problem: function relayerTextObjs() { var objs = findObjs({ type: "text" }); var index = 0; _.each(objs, function(obj){ objs[index].set("layer",""); index = index + 1; }); } The code is a little sloppy, but it works. It will reset all text objects it gets though, so feel free to include any other filters in the findObjs function.
1411516257
DXWarlock
Sheet Author
API Scripter
I had the same happen, its this part of your script layer: "Map & Background", there is no layer called that. I did it with a token, and had to have Riley fix it :( Hopefully the code Charles gave can get it working for you without having to bug RIley like I did.
It did. I'm the OP, I was just letting everyone know that I'd managed to resolve the problem so other people didn't spend their valuable time on this issue.
1411575702

Edited 1411585117
The Aaron
Roll20 Production Team
API Scripter
You can simplify that function a bit: function relayerTextObjs() { _.each(findObjs({type: "text"}), function(obj){ obj.set("layer",""); }); } The obj parameter is the object you are wanting to adjust, so you can just call set() on it.
1411580899

Edited 1411580911
DXWarlock
Sheet Author
API Scripter
Charles H. said: It did. I'm the OP Well I'll be..you are aren't you? Dont I feel like a dunce now..haha
@Aaron: TY for cleaning it up. On another note, does anyone know how to make an item visible even if there's dynamic lighting or fog of war there? Currently it dumps this time clock into the upper left corner of the map on the token layer, but players can't see it unless that part of the map is visible.
1411585090
The Aaron
Roll20 Production Team
API Scripter
I would add an invisible token there that sheds a light and all players can see/control it. Then I'd put a box around it on the Dynamic Lighting Layer.