Problem to declare arrays

Former Member
Former Member
I am trying and keep failing to declare a few arrays in my code.

The error message looks like
BUILD: ERROR: stdin:8027: Redefinition of label (code) _Users_karsten_Documents_Research_Code_workspace_Golf_SC_source_Golf_courses_mc_12_0
BUILD: ERROR: stdin:8105: Redefinition of label (code) _Users_karsten_Documents_Research_Code_workspace_Golf_SC_source_Golf_courses_mc_13_0
BUILD: Complete


and similar, depending on the details how and where I declare what.

The following code fragments all failed to compile in a similar way:
var course_vp = new[18];
var course_lon = new[18];
var course_lat = new[18];
var course_par = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3];
var This_Course = [course_vp, course_lon, course_lat, course_par];


and

var course_vp = [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false];
var course_lon = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
var course_lat = new[18];
var course_par = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3];
var This_Course = [course_vp, course_lon, course_lat, course_par];



and

var This_Course = [new[18],new[18], new[18], new[18]];



Any ideas what the error message means and how to fix it? Any other suggestions how to declare a data structure with 18 sets of 4 parameters?
  • Former Member
    Former Member over 10 years ago
    Are the 180.000000 values lat/lon values from the positioning module? If they are, they are doubles, which are not yet supported for serialization, and cannot be added to the object store. If you use Location.toDegrees()[0].toFloat() instead of Location.toDegrees()[0], you should be able to save the value to your object store. Converting lat/lon to float does introduce a small amount of quantization error.
  • Former Member
    Former Member over 10 years ago
    Are the 180.000000 values lat/lon values from the positioning module? If they are, they are doubles, which are not yet supported for serialization, and cannot be added to the object store. If you use Location.toDegrees()[0].toFloat() instead of Location.toDegrees()[0], you should be able to save the value to your object store. Converting lat/lon to float does introduce a small amount of quantization error.


    Oh yes, that worked. I can store the latitudes and longitudes as Location.toDegrees()[0].toFloat(), load them later on.

    However, now I'm struggling to get the saved floats back into an info.position variable. For example, I tried (among other things):

    if( Toybox has :Position ) {
    loc_info = Position.getInfo();
    loc_info.position[0] = This_Course[ilat][hole-1];
    loc_info.position[1] = This_Course[ilon][hole-1];
    }



    I basically need to coordinates that can be used to compute the distance between them (the code to compute the distance exists already and works fine elsewhere in the app, where I use two info.position objects obtained along the track). I'm afraid I woul dhave to create an instance of an object and initialize it with the stored coordinates, but I can't figure out how to do that.

    If I could make any sense out of this (found in the doc file):

    //! Constructor: create a coordinate based off an options hash table //! @param [Dictionary] options Hash table of options
    //! @option options [Number] :latitude The latitude
    //! @option options [Number] :longitude The longitude
    //! @option options [Symbol] :format The format of lat/long (possible //! values are :degrees, :radians, or :semicircles)
    function initialize(options);



    Could someone translate the gibberish into an example (a line of code with placeholders), please?
  • I'm using your distance code, and what I did was change it so that it was passed lat1,lon1,lat2,lon2 instead of info.position objects. That was I can calculate the distance between where I am and a number of waypoints.

    Thanks again for the code. It works quite well for me!
  • now I'm struggling to get the saved floats back into an info.position variable. For example, I tried (among other things)... Could someone translate the gibberish into an example (a line of code with placeholders), please?


    It looks like you're trying to do this...

    var location = new Position.Location({
    :latitude => This_Course[ilat][hole - 1],
    :longitude => This_Course[ilon][hole - 1],
    :format => :degrees
    });


    I don't know that it is very useful to do that though because you're just going to turn around and pass that data to a function that calculates distance and direction. If that was my project, I'd do as suggested by jim_m_58 and just update your distance/direction code to take positions as broken down lat/lon values. If you feel it is useful, you could add a helper that takes a Position.Location, extracts the lat/lon in radians and then calls the helper function.

    Travis