question

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie asked Matthew Gillespie answered

How do I create a multi-dimensional array?

FlexSim 17.0.0
flexscriptarray
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Matthew Gillespie avatar image
2 Likes"
Matthew Gillespie answered

In FlexSim 2017 we added a new Array type that holds Variants (a Variant can hold an int, double, string, treenode or Array). This allows you to store an Array as an element of another Array and, thus, make multi-dimensional arrays. There are a few ways you could do this:

Assign an array to another array element

Array myArray = Array(5);
myArray[1] = [1, 2, 3];

Push an array onto another array

myArray.push(["Yes", 5, "No"]);

Fill the array with another array (The fill command puts the given value into every element of the array)

myArray.fill([1, 2, 3]);

Accessing Elements

Once you have a multi-dimensional array set up you use bracket notation to access individual elements.

int x = myArray[3][4];  // Gets the value of the 4th element in the array in the 3rd element of myArray.
myArray[1][2][3] = 5;  // Sets the value of the 3rd element in the array in the 2nd element of the array in the 1st element of myArray.
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.