Arrays

Learn here how to use arrays to your advantage! Arrays give sequential order to an otherwise disorganized set of data for simpler DS manipulation. For example, if you have a playlist of songs for your Dream, but the music files are all out of order (m4, m72, m2, m34, m16, etc), or you have an NPC in your Dream that gives a random statement when bumped, arrays can be useful here to not only organize your data effectively, but also will allow you to accomplish your goal using less DS lines.

What is an array?

An array is a type of variable or string that orders multiple numbers (variables) or pieces of text (strings) within itself. They can do the same thing as variables and strings, but they have a lot of uses beyond that, as you'll see here!

How is an array set up?

Before you start, an array has to be set up first. You can use the (5:276) line to set up arrays that use strings, and (5:311) for arrays that use variables.

(5:276) use message ~StringArray[5] as an array, and set entry 0 of it to {First Entry.}.
(5:311) use variable %NumericalArray[5] as an array, and set entry 0 of it to 1.

Array size and entries

Here is each element one by one! We'll use the following as our example:

(5:276) use message ~StringArray[5] as an array, and set entry 0 of it to {First Entry.}.
(5:311) use variable %NumericalArray[5] as an array, and set entry 0 of it to 1.

The first thing to decide is how big you need your array to be, as they can only hold a set number of entries, and however many you decide to use has to be declared when the array is first added to the DS. So, in both examples, we made 2 arrays, one called ~StringArray and the other %NumericalArray. Each have 5 entries within themselves.

Note: Array sizes can't be initialized by variables. In other words, %NumericalArray[%Size] or ~StringArray[%Size] may not be used. This not only will mess up your arrays, but also count towards your variable/string limits.

It's only necessary to set the size of the array during the very first time the array appears in the DS, so you don't have to keep defining it over and over again.

Each entry within an array of either type can work just like regular strings or variables, only now they're organized! But, of course, there is a catch, too. Every entry you add to an array does also count towards the total limit of strings and variables in the Dream.

Array entries and their properties

Now we will look at setting entries:

(5:276) use message ~StringArray[5] as an array, and set entry0 of it to {First Entry}.
(5:311) use variable %NumericalArray[5] as an array, and set entry 0 of it to 1.

This tells which entry you are introducing data into. In the example, we are setting the very first entry (index number 0) to be First Entry in ~StringArray and then in %NumericalArray we set the first one to be 1.

As you'll notice, arrays start at 0! This is because entry 0 is also a valid entry. In other words, in our examples, ~StringArray has entries 0 through to 4 within itself, and so does %NumericalArray.

One of the most useful aspects to arrays is that entries also accept variables! For example, let's say we have a variable called %TheAmigos that holds the number 3 within itself:

(5:276) use message ~StringArray[5] as an array, and set entry %TheAmigos of it to {Third Entry.}.
(5:311) use variable %NumericalArray[5] as an array, and set entry %TheAmigos of it to 3.

In this example, the array will be declared as usual, with 5 entries (starting from Entry 0), however, it will be Entry 3 within ~StringArray that receives the value Third Entry and also Entry 3 that receives the value 3 within %NumericalArray.

Account E-Mail

Password