weird overwrite with solarintensity

I coded stats has solarintensity even created a bool of hasSolar extra and build a Array with nonsolar and solarvalues, the diveded the dataArray . the also coded data!=?data:0 but ever got a error on non solardevices the code is for an arc 

here the "catch the null of the null without nully null nulls", and at HEEERRRREEEE it crashes at non solar devices!!!!!!! it should never went into has :solarintensity

    var factor = 0.4;

    var solint = null;
  
    if(stats has :solarIntensity)
    {
      solint = stats.solarIntensity;
    }
      arcArray = [
        [ ((batter * factor)!= null?(batter * factor).toNumber():0), "BA" ],
        [ ((stepPercent * factor)!= null?(stepPercent * factor).toNumber():0), "ST" ],
        [ (solint*factor)!=null?(solint*factor).toNumber():0,"SO" ], // HHHEEEEEERRRRRRRRRRREEEEEEEE
        [ ((stress * factor)!= null?(stress * factor).toNumber():0), "ST" ],
        [ ((bodyBat * factor)!= null?(bodyBat * factor).toNumber():0), "BB" ]
      ];
  • As per the API docs, ActivityInfo.Stats.solarIntensity can be null.

    https://developer.garmin.com/connect-iq/api-docs/Toybox/System/Stats.html#solarIntensity-var

    In that case, solint*factor will crash [multiplication is not supported for null values].

    Try the following change:

            [ solint !=null ? (solint * factor).toNumber() : 0, "SO" ],

    There is no point in checking whether X * Y is null at all [as you have done above for every single member of the array].

    Either:

    - X and Y are both Numeric [Number, Long, Float, Double] and the multiplication succeeds

    or

    - one of X or Y is non-Numeric [e.g.null], and the multiplication causes a crash [rather than returning null]

  • So a more complete fix might look like this:

    arcArray = [
      [batter != null ? (batter * factor).toNumber() : 0, "BA"],
      [stepPercent != null ? (stepPercent * factor).toNumber() : 0, "ST"],
      [solint != null ? (solint * factor).toNumber() : 0, "SO"],
      [stress != null ? (stress * factor).toNumber() : 0, "ST"],
      [bodyBat != null ? (bodyBat * factor).toNumber() : 0, "BB"]
    ];

    Ofc it may be that some of those other values can never be null, making some of those checks needless.

    Another issue is that when a value is unavailable, you don't necessarily want to display "0" in your app. e.g. On my Garmin's native watchface, if I remove the watch from my wrist, the HR and body battery fields display "--".

    Yet another potential issue is that you use the same abbreviation for step % and stress ("ST"). This may be confusing to users.

  • thought null*2 is null!!!

  • thought null*2 is null!!!

    Not in Monkey C. In Monkey C, null * 2 is an error. If you doubt this, you should test it for yourself (please don't take my word for it). However, it does explain why your code is crashing.

    tbh idk where that assumption comes from.

    For example:

    - in java, null * 2 is a compile time error

    - in js, null * 2 results in 0

    - in python, None * 2 is a TypeError