I have a working clock in Javascript here:
I’m trying to adapt that to a watch face. Note that the font I am using renders a character “XI” for “|” and such.
What is wrong with this:
const hours = (now.getHours() % 12 || 12);
switch(hours) {
case 1:
hour = "1";
break;
case 2:
hour = "2";
break;
case 3:
hour = "3";
break;
case 4:
hour = "4";
break;
case 5:
hour = "5";
break;
case 6:
hour = "6";
break;
case 7:
hour = "7";
break;
case 8:
hour = "8";
break;
case 9:
hour = "9";
break;
case 10:
hour = "{";
break;
case 11:
hour = "|";
break;
case 12:
hour = "}";
break;
default:
hour = "0";
}
const timeStr = hour;
// Draw time centered
let width = render.getTextWidth(timeStr, timeFont);
render.drawText(timeStr, timeFont, white,
(render.width - width) / 2, timeY);
The log says:
[VERBOSE] xsHost.c:155: Found mod "pebble.moddable.tech"
[ERROR] xsPlatform.c:209: undefined
[ERROR] xsPlatform.c:217: fxAbort unhandled exception: get hour: undefined variable
[VERBOSE] xsHost.c:155: Found mod "pebble.moddable.tech"
[ERROR] ault_handling.c:98: App fault! {2cee2995-751e-4446-a63a-fa262a886b88} PC: 0x5 LR: ???
[ERROR] xsPlatform.c:209: undefined
[ERROR] xsPlatform.c:217: fxAbort unhandled exception: get hour: undefined variable
[ERROR] ault_handling.c:98: App fault! {2cee2995-751e-4446-a63a-fa262a886b88} PC: 0x5 LR: ???
I suspect I am not assigning hour correctly in this case statement for this system. Assuming I can even use a case statement as shown.