# DataType:array

Data related to arrays. **Note:** Array indexing starts at **1**

## Members

| **Type**                                                                                       | **Member**       | **Description**                                                   |
| ---------------------------------------------------------------------------------------------- | ---------------- | ----------------------------------------------------------------- |
| [*int*](/macroquest/data-types-and-top-level-objects/data-types/datatype-int.md)               | **Dimensions**   | Number of dimensions in the array                                 |
| [*int*](/macroquest/data-types-and-top-level-objects/data-types/datatype-int.md)               | **Size**         | Total number of elements in the array                             |
| [*int*](/macroquest/data-types-and-top-level-objects/data-types/datatype-int.md)               | **Size\[**#**]** | Total number of elements stored in the #th dimension of the array |
| \_\_[*string*](/macroquest/data-types-and-top-level-objects/data-types/datatype-string.md)\_\_ | **To String**    | *None*                                                            |

## Declare Arrays

To create an array, attach square brackets to the end of the variable name and place in it the number of elements per dimension.

**Array Examples**

1. This creates a single-dimension local array of int with 10 elements (1-10) all 0:

```
/declare MyArray[10] int
```

This creates a 2-dimensional 10x10 elements(1-10,1-10) int array of scope outer with all values of 5:

```
/declare MyArray[10,10] int outer 5
```

This creates a 3-dimensional array with 4x5x6 elements (1-4,1-5, 1-6) with UNDEFINED-ARRAY-ELEMENT in each location:

```
/declare MyArray[4,5,6] string outer UNDEFINED-ARRAY-ELEMENT
```

There is no limit to the number of dimensions or the number of elements in each dimension, but use your own good judgement.

**Note:** You cannot make an array of timers.

## Example Snippets

```
sub main
        /declare myArray[9] int local 0
        /declare myCounter int local

        /echo =============[Put Data]=================
        /for myCounter 1 to ${myArray.Size}
                /varset myArray[${myCounter}] ${Math.Rand[999]}
                /echo Put a random number in Index ${myCounter} of myArray
        /next myCounter

        /echo =============[Get Data]=================
        /for myCounter 1 to ${myArray.Size}
                /echo Index ${myCounter} in myArray is ${myArray[${myCounter}]}
        /next myCounter
/return
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://macroquest.gitbook.io/macroquest/data-types-and-top-level-objects/data-types/datatype-array.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
