ARRAY VARIABLES

shawn_crocker
shawn_crocker Member, OS Professional Posts: 1,064 PRO
I'm having a hard time creating an array that has a dimensional size defined by another variable
    var partCount = size(evaluateQuery(context, definition.sheetMetalParts));
    var flatSizes = [partCount];
When I try to store things into flatSizes, [0] dimension takes a value but when the code loops back to store something in [1], I get a "Array index 1 out of bounds.".  It feels like I not defining the array size properly.

flatSizes[i] = getExtents(boundingBox, 3, inch);That is how I'm trying to store the map values.  I'v been searching and am not finding clear answers on this one.

Best Answer

  • Alex_Kempen
    Alex_Kempen Member Posts: 258 EDU
    edited June 2021 Answer ✓
    You're currently making an array containing the variable partCount. Accordingly, flatSizes always contains a single element, so it always has a size of 1. To make flatSizes properly, use makeArray instead.
    Software Developer at Epic Systems
    FRC Design Mentor - Team 1306 BadgerBots


Answers

  • Alex_Kempen
    Alex_Kempen Member Posts: 258 EDU
    edited June 2021 Answer ✓
    You're currently making an array containing the variable partCount. Accordingly, flatSizes always contains a single element, so it always has a size of 1. To make flatSizes properly, use makeArray instead.
    Software Developer at Epic Systems
    FRC Design Mentor - Team 1306 BadgerBots


  • shawn_crocker
    shawn_crocker Member, OS Professional Posts: 1,064 PRO
    @Alex_Kempen your a life saver. Thanks again.