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
    All of these compile for me using the 1.1.1 SDK. What SDK version are you using? What lines of code are on line 12 and 13 directly?

    On a side note, have you considered creating a Course object with a list of Hole objects that each have a vp, lon, lat and par value? It might make the code cleaner/easier to maintain. I'm not sure about the memory footprint difference though.
  • Former Member
    Former Member over 10 years ago
    The error message was created by the first example, and lines 12 and 13 read:

    var course_vp = new[18]; //[false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false];
    var course_lon = new[18]; //[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];


    But the other variations I copied above give similar error messages. No matter whether declared by new[] or initialized with values. The funny thing is that the error messages are not at all consistent and seem to stumble upon some but not all array declarations.

    I'll restart Eclipse - maybe something is messed up there.

    About your suggestion to create a Course object: I didn't try. I'm not a professional developer and didn't have an immediate idea how to do it and what the advantages might be (if any).
  • Former Member
    Former Member over 10 years ago
    Problem disappeared - not understood why.

    I just re-arranged the lines a bit. Copy and paste here, delete a blank line there, add a blank line elsewhere. In particular line 13 is now emtpy.

    Works.

    No clue why.

    Thanks for listening...
  • Former Member
    Former Member over 10 years ago
    Now I can modify my little 2-D array and use it in the code, but I get an error message when I try to store it in the properties. Here is the error message:

    Above the error message is the actual contents of the array (the first 4 lines are the 4 sub-arrays, each 18 elements wide).
    The next line is the key that I use for the property: "Course 0".

    The code that creates the error is given below.

    [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]
    [180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000]
    [180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000]
    [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
    Course 0
    Failed invoking <symbol>
    Unexpected Type Error
    in setProperty (/Users/lahm/Desktop/Monkeybrains/toolchain/mbsimulator/submodules/technology/monkeybrains/virtual-machine/api/Application.mb:80)
    in setProperty (/Users/lahm/Desktop/Monkeybrains/toolchain/mbsimulator/submodules/technology/monkeybrains/virtual-machine/api/Application.mb:80)
    in loadThisCourse (/Users/karsten/Documents/Research/Code/workspace/Golf_SC/source/Golf_courses.mc:50)
    in onStart (/Users/karsten/Documents/Research/Code/workspace/Golf_SC/source/Golf_SCApp.mc:122)



    The code that creates the error is here:


    function loadThisCourse(course_no) {
    var lc = null;
    var This_App = App.getApp();
    var Prop_Key;
    Prop_Key = "Course " + course_no.toString();
    Sys.println(Prop_Key);
    lc = This_App.getProperty(Prop_Key);
    if (lc == null) {
    lc = This_Course;
    This_App.setProperty(Prop_Key, This_Course);
    This_App.saveProperties();
    }
    This_Course = lc;
    }
  • I've tried to reproduce this using arrays and nested arrays similar to your [FONT=Lucida Console]This_Course[/FONT] array and basically using the cuntion code you supplied (I had to mock a couple of things), but so far I haven't had any issues.

    In the following code:

    1 function loadThisCourse(course_no) {
    2 var lc = null;
    3 var This_App = App.getApp();
    4 var Prop_Key;
    5 Prop_Key = "Course " + course_no.toString();
    6 Sys.println(Prop_Key);
    7 lc = This_App.getProperty(Prop_Key);
    8 if (lc == null) {
    9 lc = This_Course;
    10 This_App.setProperty(Prop_Key, This_Course);
    11 This_App.saveProperties();
    12 }
    13 This_Course = lc;
    14 }


    What is the value of [FONT=Lucida Console]This_Course [/FONT]on line 9? My guess is that when you try to set the property on line 10, the type of [FONT=Lucida Console]This_Course[/FONT] is not valid. Properties must be one of String, Number, Float, or Boolean. It can also be null or an Array or Dict containing one of the valid types. Is it possible that an invalid type is sneaking into one of your arrays?
  • Bad hawken! Hawken is actually me. Sorry about that! :o
  • Former Member
    Former Member over 10 years ago
    In the following code:

    1 function loadThisCourse(course_no) {
    2 var lc = null;
    3 var This_App = App.getApp();
    4 var Prop_Key;
    5 Prop_Key = "Course " + course_no.toString();
    6 Sys.println(Prop_Key);
    7 lc = This_App.getProperty(Prop_Key);
    8 if (lc == null) {
    9 lc = This_Course;
    10 This_App.setProperty(Prop_Key, This_Course);
    11 This_App.saveProperties();
    12 }
    13 This_Course = lc;
    14 }


    What is the value of [FONT=Lucida Console]This_Course [/FONT]on line 9? My guess is that when you try to set the property on line 10, the type of [FONT=Lucida Console]This_Course[/FONT] is not valid. Properties must be one of String, Number, Float, or Boolean. It can also be null or an Array or Dict containing one of the valid types. Is it possible that an invalid type is sneaking into one of your arrays?


    You can see the contents of This_Course in one of my posts above, where I reproduce the console, and the first 4 lines are the four arrays that make up This_Course. They carry all the values I had given them during initializing in a dedicated function. The first array is false for all 18 elements, then 180.00 for the next two arrays, and finally 18 x 3. Nothing suspicious I think...

    The whole code fragment tries to prevent app crashes that seem to happen when non-existing properties are 'read' from storage.
    The two topmost errors - i.e. the last two statements that are executed before the crash are obviously not in my code but in the library (virtual machine). I had hoped you could simply look at the reported lines and check what goes wrong there?
  • Isn't the Object Store limited to 8k? And not just 8k of data, as the data and keys are stored, along with things like object types and size. Could this me a "max" problem with the size of the data store?

    Could the 8k a maximum, which could be smaller based on the 64k limit for an app overall?
  • The whole code fragment tries to prevent app crashes that seem to happen when non-existing properties are 'read' from storage.
    The two topmost errors - i.e. the last two statements that are executed before the crash are obviously not in my code but in the library (virtual machine). I had hoped you could simply look at the reported lines and check what goes wrong there?


    Yep, this is what I did. The error appears to occur when your app tries to write the This_Course data to the object store, which is why I was suspecting some invalid type polluting your data.
  • Former Member
    Former Member over 10 years ago
    Yep, this is what I did. The error appears to occur when your app tries to write the This_Course data to the object store, which is why I was suspecting some invalid type polluting your data.


    Thanks so far. I just don't see anything invalid. The whole "This_Course" array looks like

    [
    [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false],
    [180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000],
    [180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000, 180.000000],
    [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
    ]



    "false" has been saved as the boolean keyword, not as a string - just to be clear about that:

    ivp= false;

    not

    ivp= "false";