Back to Tips Page

ARRAYS

Arrays are like a spreadsheet. They contain "cells" of information that you can use for storage (just like a variable can). They're quite handy when you want to store multiple information, typically related to a single source.

Arrays can be just rows, or a combination of rows and columns. There are two commands and one procedure that are used when handling arrays: "/array", "/assign", and "@GetArray()"

/array {Name to call it} {rows} {group} -- creates a row-only array.
This creates an array that is just rows (one "cell" of info per row). A "row-only" array is handy when you don't need a lot of cells to store info in.
/array {MyArray} {5} -- creates "MyArray" with 5 rows (will hold 5 cells of info), just like creating 5 variables. Picture this like:
Row
 1 [info]
 2 [info]
 3 [info]
 4 [info]
 5 [info]
/array {Name to call it} {rows,columns} {group} -- creates a row and column array.
This creates an array using both rows and columns. Just like a spreadsheet.

/array {MyArray} {3,4} -- creates "MyArray" with 3 rows and 4 columns. A total of 12 cells of info.
Picture it as:
          1      2      3      4   <-Column
Row
 1      [info] [info] [info] [info]
 2      [info] [info] [info] [info]
 3      [info] [info] [info] [info]
/assign {Name of the array} {row} {info to store} -- put info into the array at a given row. (for row-only array)

"/array" only creates the template, you now need to put info into the cells. That's where "/assign" comes into play.
/assign {MyArray} {4} {Info to store}
This would assign some string to the row-only array, at row 4

/assign {Name of the array} {row,column} {info to store} -- put info into the array at a given row and column.

/assign {MyArray} {2,3} {Info to store}
This would assign some string to row 2, column 3's cell.
Note: Trying to use a row-only /assign call on an array that has both rows AND columns will NOT work.

@GetArray(ArrayName,Row,Column) -- extract the stored info from an array at a given row.
After you've made your array and put info into the cell(s), you need a way to retrieve that info. Thus we have the "@GetArray()" proc.

@GetArray(MyArray,1) -- for a row-only array, get the info from row 1. Note: Mud Master Help files say that you have to use
"@GetArray(Name,row,0)" to get info from a row-only array -- well you don't need the 0, but could use it. "@GetArray(MyArray,1,0)" is the same as "@GetArray(MyArray,1)".

@GetArray(MyArray,3,15) -- for a row&column array, get the info stored at row 3, column 15's cell.

Tips
Have an idea of how you want to structure the array. How many rows, columns do you need (you can always alter the array's size and info in an editor like NotePad or WordPad).

Remember what goes where. An array that's 5 rows by 10 columns is FIFTY cells of info. Scribble notes about what info is in what row&column. And/or make a variable as a reminder: /var {MyArrayINFO} {MyArray is 5rows by 7cols, row 1 is scores, cols 1 is kills, 2 is deaths, 3 is....}. It's easy to forget WHAT goes where in an array, or when looking at the array you might say "hmm row 3, col 7 = 1029, but what IS 1029??" Notes or a reminder variable helps a lot.

Arrays are pretty fast (they used to be very slow). And they are a great method for storing lots of information.

Array cells are EMPTY at creation (eg: using the "/array" command). Just like empty variables ("/empty" command) they will not process if you happen to try to use them. That is, if you create an array, but don't assign anything to the array's cell, then you try to use that cell via @GetArray(), it'll fart out -- In most cases anyway.
One exception: You can use @IsEmpty(@GetArray(Name,Row,Col)) to see if an array cell IS empty.
So... it's best to assign some generic values to cells when you create the array. Typically "0" works for most stuff, or just some garbage string like "null" or "xxx" or whatever.

The name of the array can contain whitespace: /array {this is my array} {2,2}. And or numbers, just don't use a number as the FIRST character of the array's name: /array {MyArray3} {2,2}, or /array {Trade Post 23 prices} {6,11}.

Back to Tips Page