WorkoutIntervalStep

Hi!

I have a datafield for cyclists, which - among other thinfs - monitors laps.
I encountered, that for workouts there is no lap event when you go to the next interval.

Now I tried to get Activity.WorkoutIntervalStep.repetitionNumber to check if I can use this, but I get an error:

        var mValue = "--";
        if ( Activity has :WorkouIntervalStep) {
            if ( WorkoutIntervalStep.repetitionNumber != null ) {
                mValue = WorkoutIntervalStep.repetitionNumber.format("%0d");
            }    

        }

I get an error in line 3:

ERROR: edge1050:
Cannot find symbol ':repetitionNumber' on class definition '$.Toybox.Activity.WorkoutIntervalStep'.

What do I miss?

Thanks!

  • According to the documentation:

    Activity.getCurrentWorkoutStep() as Activity.WorkoutStepInfo or Null,

    WorkoutStepInfo.step as Activity.WorkoutStep or Activity.WorkoutIntervalStep

    so you need to check step and if it's WorkoutIntervalStep then check for step.repetitionNumber

  • There's two problems with your code:

    1) "Activity has :WorkouIntervalStep" <= typo. (But this code isn't necessary in any case, as you'll see.)

    2)

    if ( WorkoutIntervalStep.repetitionNumber != null ) {
          mValue = WorkoutIntervalStep.repetitionNumber.format("%0d");
    }   

    Here you're apparently trying to use the WorkoutIntervalStep class directly, instead of getting an instance of the class. The reason you're getting that type checking error ("Cannot find symbol...") is because repetitionNumber is an instance member, not a static member, which means in order to access it you need an instance of the class, as opposed to accessing it through the class itself. (I will say that the error message def has room for improvement. In an ideal world it would say that repetitionNumber exists on WorkoutIntervalStep, but you need an *instance* of WorkoutIntervalStep as opposed to trying to access the member statically).

    (Given that a workout can have many steps, it should be expected that you need a class instance to access related data. Not to mention the fact that there's very few - if any - examples of static member variables in the Connect IQ API, as opposed to static functions.)

    https://en.wikipedia.org/wiki/Member_variable

    In class-based programming languages, these are distinguished into two types: class variables (also called static member variables), where only one copy of the variable is shared with all instances of the class; and instance variables, where each instance of the class has its own independent copy of the variable.[1]

    The solution is to make the appropriate call to get an instance of the current workout step, and from there, to get an instance of the current workout interval step:

    var mValue = "--";
    if (Activity has :getCurrentWorkoutStep) {

      var step = Activity.getCurrentWorkoutStep();
      if (step != null && step instanceof Activity.WorkoutIntervalStep) {
        mValue = step.repetitionNumber.format("%0d");
      }
    }

  • I encountered, that for workouts there is no lap event when you go to the next interval.

    Use onWorkoutStepComplete(). As you've noticed, onTimerLap() does not fire at the end of a workout step.

  • Thank you, both, for explaining and clarification.

    Since I was looking for an alternative to onTimerLap() - thanks for pointing me to onWorkoutStepComplete(). That‘s it!