get calories not working

Former Member
Former Member

This is how I get the number of burnt calories throughout the day in my code:

calorieStatus = ActivityMonitor.getInfo().calories

When testing with the simulator, since there was no way to set calories in the simulator, I wasn't able to test it. But I uploaded a beta version and on my watch, that get-calories method does not work.

This is the full calories code:

	var calorieGoal = UserProfile.getProfile().gender == 0 ? 2000 : 2500;
		var calorieStatus;
		if(ActivityMonitor.getInfo().calories <= 0)  {
			calorieStatus = 0;
		} else if(ActivityMonitor.getInfo().calories >= calorieGoal) {
			calorieStatus = 1;
		} else {
			calorieStatus = ActivityMonitor.getInfo().calories / calorieGoal;
		}

Where the point is to fill a bar out of 100%, so that is why I am using numbers from 0 to 1.

  • Assume calorieGoal=2000 and current calories is 1000

    Sys.println("n="+1000/2000+" "+ 1000/2000.toFloat());

    resullts in:

    n=0 0.500000

    you're dividing a number by a number and getting a number, where you really want a float.

  • you're dividing a number by a number and getting a number, where you really want a float.

    Just to round out this thought... Integer (Number or Long in MonkeyC) division results in an integer, and it will always get rounded (toward zero) to the nearest whole number. This is how integer arithmetic works in most programming languages.

    If you want a floating point result, you need to make one or more of the operands in the division are a floating point type (Float or Double).

    As an additional note, your code is calling ActivityMonitor.getInfo() up to three times in the normal case. You can save yourself some code space and some performance by just calling it once and caching the result in a local variable.