(Beginner's question) Data Field first project

Former Member
Former Member
Hello

I am fairly new to programming, so probably Monkey C is a long shot for me, but I wanted to give it a try. After a few hours spend looking through samples and forum, I have decided that it would be easier just to ask.

The code that I am posting here is going to be just a base for me to understand how to implement various activity infos into the screen. Eventually I would like to end up with 8 different values displayed on one data field.

using Toybox.WatchUi as Ui;
using Toybox.Graphics as Gfx;
using Toybox.System as Sys;
using Toybox.Activity as Act;

class UUView extends Ui.DataField
{
var bla1;
var info;

function initialize()
{
}

function onUpdate(dc)
{
info = Act.getActivityInfo();

if( info.elapsedTime != null )
{
bla1 = info.elapsedTime;
}
return bla1;
dc.clear();
dc.setColor( Gfx.COLOR_WHITE, Gfx.COLOR_RED );
dc.drawText( 11, 11, Gfx.FONT_SMALL, bla1, Gfx.TEXT_JUSTIFY_LEFT );
}
}



Eclipse compiles the code just fine, but after running it on simulator, I get no red background color, or anything else displayed, just white screen on watch in simulator.

Please help me figure that out. I bet it is simple and I am dumb :)
  • The problems are pretty simple.

    function onUpdate(dc)
    {
    info = Act.getActivityInfo();

    if( info.elapsedTime != null )
    {
    bla1 = info.elapsedTime;
    }

    // execution of this function terminates after the following line. the return
    // statement tells the environment that to immediately return to the calling
    // function, which means none of the code below is reachable.
    return bla1;

    // none of this code is reachable....

    // you should call dc.setColor(...) before calling clear. if you don't
    // you have no idea what you just reset the screen color to.
    dc.clear();
    dc.setColor( Gfx.COLOR_WHITE, Gfx.COLOR_RED );

    // be careful about passing objects that are not strings to functions
    // that expect strings. in this case `blah1' is a Toybox.Lang.Number.
    // i'm can't recall if this will cause problems or not, but it is a good
    // idea to be explicit here and pass a string. to do this, you can write
    // `blah1.toString()' or `blah1.format("%d")'
    dc.drawText( 11, 11, Gfx.FONT_SMALL, bla1, Gfx.TEXT_JUSTIFY_LEFT );
    }