Error: Unhandled Exception Exception: UnexpectedTypeException: Expected Symbol, given Number Stack: - onTap() at C:\Users\User\eclipse-workspace\MyProjects\Map Widget\source\MapWidgetDelegate.mc:49 0x10001418 - handleEvent() at T:\mbsimulator\submodules\technology\monkeybrains\virtual-machine\api\WatchUi.mb:1060 0x300022b5 - handleEvent() at T:\mbsimulator\submodules\technology\monkeybrains\virtual-machine\api\WatchUi.mb:1266 0x300024a4
The problem is located at all four variants of: g[1] = (g[1] - 1.0);
(Just so you know what g means: g = Position.getInfo().position; and is a global variable in the delegate and a variable in onUpdate in the view.
g[1] and g[0] indicate latitude and longitude of said position which i am trying to add to or take away 1.0 from on a tap up down left or right to change the position info and thus my view.
However I need help as I do not understand why it is going wrong as I am a bit of a coding noob (much of the code is open source that I am adding onto. Thanks for any help.
on tap part of Delegate
function onTap(clickEvent) {
var coord = clickEvent.getCoordinates();
var x = coord[0];
var y = coord[1];
if (posnInfo != null) {
if(x > 0 && x < 60 && y > 40 && y < 200)
{
System.println("left");
g[1] = (g[1] - 1.0);
WatchUi.requestUpdate();
}
else if(x > 180 && x < 240 && y > 40 && y < 200)
{
System.println("right");
g[1] = (g[1] + 1.0);
WatchUi.requestUpdate();
}
else if(x > 60 && x < 180 && y > 0 && y < 60)
{
System.println("up");
g[0] = (g[0] + 1.0);
WatchUi.requestUpdate();
}
else if(x > 60 && x < 180 && y > 180 && y < 240)
{
System.println("down");
g[0] = (g[0] - 1.0);
WatchUi.requestUpdate();
}
else
{
System.println("cl");
WatchUi.requestUpdate();
}
}
else
{
System.println("no");
}
On update and set position part of View
function onUpdate(dc) {
var string;
var width;
var height;
var screenWidth = dc.getWidth();
var heading = Sensor.getInfo().heading;
var minuteHandAngle;
var targetDc = null;
var targDc = null;
var r;
var g = Position.getInfo().position;
View.onUpdate(dc);
if (null != offscreenBuffer) {
dc.clearClip();
curClip = null;
// If we have an offscreen buffer that we are using to draw the background,
// set the draw context of that buffer as our target.
targetDc = offscreenBuffer.getDc();
targDc = offscreenBuffer.getDc();
}
else
{
targetDc = dc;
targDc = dc;
if (g!=null)
{
g = g.toDegrees();
find(g[0], g[1]);
g = null;
for(var i=0, yy=y-imgs-my; yy<y+imgs; yy+=imgs) {
for(var xx=x-imgs-mx; xx<x+imgs; xx+=imgs, i++) {
if(ar[i]!=null) {
dc.drawBitmap(xx, yy, WatchUi.loadResource(ar[i]));
}
}
}
}
}
//Use white to draw the hour and minute hands
width = targetDc.getWidth();
height = targetDc.getHeight();
width = targDc.getWidth();
height = targDc.getHeight();
targetDc.setColor(0x0000FF, Graphics.COLOR_TRANSPARENT);
targDc.setColor(0xFF0000, Graphics.COLOR_TRANSPARENT);
minuteHandAngle = heading;
targetDc.fillPolygon(generateHandCoordinates(screenCenterPoint, minuteHandAngle, 22, 0, 8));
targDc.fillPolygon(generateHandCoordinates(screenCenterPoint, minuteHandAngle, 20, 0, 6));
dc.setColor(0x0000FF,-1);
dc.fillRectangle(x-4, y-4, 8,8);
up.draw(dc);
down.draw(dc);
left.draw(dc);
right.draw(dc);
dc.setColor( Graphics.COLOR_GREEN, Graphics.COLOR_TRANSPARENT );
if( posnInfo != null ) {
gps.draw(dc);
}
else {
dc.setColor( Graphics.COLOR_RED, Graphics.COLOR_TRANSPARENT );
dc.drawText( (dc.getWidth() / 2), (dc.getHeight() / 2), Graphics.FONT_TINY, "No position info", Graphics.TEXT_JUSTIFY_CENTER );
}
}
function setPosition(info) {
posnInfo = info;
WatchUi.requestUpdate();
Application.Storage.Position;
}
Update the view
Hope thats enough info.