Data field Newby - Formatting Madness.

I've almost finished my first Data field,  and have hit a snag with the simulator or watch or both. 

I used a DC draw variable.format in  onupdate(dc) to try and output a 3 digit integer, and for another field,  3 digit float with 1 precision.

In the SIM, I got an error in the dc field, saying found string when expecting float etc... so I moved the formatting into the oncompute section as variable = ( function ).format("%03.1f")

That removed the error, and the simulator works and looks correct.

I then re- sideloaded the app onto my watch, and the fields are not displaying as formatted... they are back to a load of zeros with decimal ?????

Should I be able to format in oncompute when setting a variable function ?

Any ideas?

  • Sounds like you may not be null checking things you get from Activity.Info (the "info" passed to compute()), and you're trying to format something that can't be formatted.  This can vary between the sim and a real device if you are playing back a fit/simulating data when you test in the sim.

  • Well.... 

    To Clarify, This code is working on the app and the watch:

    if (info has :distanceToNextPoint &&
        info.distanceToNextPoint != null &&
        info.distanceToNextPoint != 0 &&
        info.nameOfNextPoint != null)
    {
    	mDist = ( 0.000539957 * info.distanceToNextPoint ).format("%04.1f");
    }
    else
    {
    	if(info has :elapsedDistance && info.elapsedDistance != null)
    	{
    		mDist = ( 0.000539957 * info.elapsedDistance ).format("%04.1f");
    	}
    	else
    	{
    	    mDist = "";
    	}
    }

    Then I DC.Drawtext mDist. On the watch there is no next waypoint in the system, so it uses the second part of the code correctly and displays elapsed distance formatted correctly.

    This code works perfectly in eclipse garmin simulator with or without FIT data or Nav data / as needed, but on the watch it's 0.000000. 

    if (info has :currentSpeed && info.currentSpeed != null)
    {
        mSpeed = (info.currentSpeed * 1.94384).format("%03.1f");
    }
    else
    {
        mSpeed = "";
    }

    I have no idea?

    Do I need to add the datafield to a particular type of activity to get output? or should activity.info have everything in there for all activities?

    I don't get it.