MinchinWeb's MetaLibrary v.11
Library functions for OpenTTD AI (and GS) writers.
Loading...
Searching...
No Matches
_MinchinWeb_Array_ Class Reference

Array. More...

Static Public Member Functions

function Create1D (length)
 Creates a one dimensional (1-D) array.
function Create2D (length, width)
 Creates a two dimensional (2-D) array.
function Create3D (length, width, height)
 Creates a three dimensional (3-D) array.
function ToString1D (InArray, DisplayLength=true, replaceNull=false)
 Converts a one dimensional array to a nice string format.
function ToString2D (InArray, DisplayLength=true, replaceNull=false)
 Converts a two dimensional array to a nice string format.
function ContainedIn1D (InArray, SearchValue)
 Searches an array for a given value.
function ContainedIn2D (InArray, SearchValue)
 Searches a (two dimensional) array for a given value.
function ContainedIn3D (InArray, SearchValue)
 Searches a (three dimensional) array for a given value.
function ContainedIn1DIn2D (InArray2D, SearchArray1D)
 Searches a two dimensional array for a given one dimensional array.
function Find1D (InArray, SearchValue)
 Searches an array for a given value.
function Find2D (InArray, SearchValue)
 Searches an array for a given value.
function Find3D (InArray, SearchValue)
 Searches an array for a given value.
function RemoveValueAt (InArray, Index)
 Removes an element from the array.
function InsertValueAt (InArray, Index, Value)
 Adds an element from the array.
function ToStringTiles1D (InArrayOfTiles, ArrayLength=false, replaceNull=false)
 Converts a one dimensional array of tiles to a nice string format.
function ToStringTiles2D (InArrayOfTiles, ArrayLength=false, replaceNull=false)
 Converts a one dimensional array of tiles to a nice string format.
function FindPairs (InArray2D, SearchValue1, SearchValue2)
 Searches an array for a given pair of values.
function ContainedInPairs (InArray2D, SearchValue1, SearchValue2)
 Searches an array for a given pair of values.
function Compare1D (InArray1D, TestArray1D)
 Compares the two arrays item for item.
function Append (Array1, Array2)
 Appends one array to another.
function RemoveDuplicates (Array)
 Removes duplicates from an array.
function ToAIList (Array)
 Turns an Array in an AIList.

Private Attributes

 main = null

Detailed Description

Array.

Version
v.7.1 (2025-07-15)
Author
W. Minchin (MinchinWeb)
Since
MetaLibrary v.6

This is a collection of functions to make working with Arrays easier.

Note
While Arrays are powerful, also consider using AIList's.

Definition at line 30 of file Array.nut.

Member Function Documentation

◆ Append()

function _MinchinWeb_Array_::Append ( Array1 ,
Array2  )
static

Appends one array to another.

Parameters
Array1the first array
Array2the second array
Returns
An array that the items has Array2 appended to the end of the items of Array1
Note
Consider using Squirrel's built-in function: MyArray.append(Item) to append individual items to an array

Definition at line 707 of file Array.nut.

◆ Compare1D()

function _MinchinWeb_Array_::Compare1D ( InArray1D ,
TestArray1D  )
static

Compares the two arrays item for item.

Returns true if every item pair matches.

Parameters
InArray1Done dimensional (1-D) array, that is considered 'known'
TestArray1Done dimensional (1-D) array, that is considered 'unknown'
Returns
true if the InArray1D and TestArray1D equal each other for the comparison of each pair of elements. false otherwise.
Note
I wrote this because I don't trust InArray == TestArray to work this way...

Definition at line 694 of file Array.nut.

◆ ContainedIn1D()

function _MinchinWeb_Array_::ContainedIn1D ( InArray ,
SearchValue  )
static

Searches an array for a given value.

Parameters
InArrayarray to search (assumed to be one dimensional (1-D))
SearchValuewhat is searched for
Returns
true if found at least once, false if not. null if InArray is null.
See also
ContainedIn1DIn2D()
ContainedIn2D()
ContainedIn3D()
Find1D()
Todo
Add error check that an array is provided

Definition at line 453 of file Array.nut.

◆ ContainedIn1DIn2D()

function _MinchinWeb_Array_::ContainedIn1DIn2D ( InArray2D ,
SearchArray1D  )
static

Searches a two dimensional array for a given one dimensional array.

Parameters
InArrayarray to search (assumed to be two dimensional (2-D))
SearchValuearray to search for (assumed to be one dimensional (1-D))
Returns
true if found at least once, false if not. null if InArray is null.
See also
ContainedIn1D()
Todo
Add error check that arrays are provided

Definition at line 498 of file Array.nut.

◆ ContainedIn2D()

function _MinchinWeb_Array_::ContainedIn2D ( InArray ,
SearchValue  )
static

Searches a (two dimensional) array for a given value.

Parameters
InArrayarray to search (assumed to be two dimensional (2-D))
SearchValuewhat is searched for
Returns
true if found at least once, false if not. null if InArray is null.
Note
using this to see if an given array is an element of the parent array does not seem to be returning expected results. Use ContainedInPairs() instead.
See also
ContainedInPairs()
ContainedIn1DIn2D()
ContainedIn1D()
ContainedIn3D()
Find2D()
Todo
Add error check that an array is provided

Definition at line 466 of file Array.nut.

◆ ContainedIn3D()

function _MinchinWeb_Array_::ContainedIn3D ( InArray ,
SearchValue  )
static

Searches a (three dimensional) array for a given value.

Parameters
InArrayarray to search (assumed to be three dimensional (3-D))
SearchValuewhat is searched for
Returns
true if found at least once, false if not. null if InArray is null.
See also
Find3D()
Todo
Add error check that an array is provided

Definition at line 481 of file Array.nut.

◆ ContainedInPairs()

function _MinchinWeb_Array_::ContainedInPairs ( InArray2D ,
SearchValue1 ,
SearchValue2  )
static

Searches an array for a given pair of values.

The idea is to provide an array of arrays of pairs (e.g. tile x and tile y, starting and ending points, etc.), and find out if SearchValue1 and SearchValue2 are among the pairs. The order that SearchValue1 and SearchValue2 are in is not considered.

Parameters
InArray2Dtwo dimensional (2-D) array
SearchValue1value to search for
SearchValue2value to search for
Returns
true if the search values are found at least once, false otherwise. null if InArray2D is null.
See also
FindInPairs()
Todo
Add error check that a 2D array is provided

Definition at line 669 of file Array.nut.

◆ Create1D()

function _MinchinWeb_Array_::Create1D ( length )
inlinestatic

Creates a one dimensional (1-D) array.

Parameters
lengththe desired length of the array
Returns
empty array of the given size
See also
Create2D()
Create3D()

Definition at line 41 of file Array.nut.

◆ Create2D()

function _MinchinWeb_Array_::Create2D ( length ,
width  )
static

Creates a two dimensional (2-D) array.

Parameters
lengththe desired length of the array (in the first dimension)
widththe desired length of the array (in the second dimension)
Returns
empty array of the given size (in two dimensions)
See also
Create1D()
Create3D()

Definition at line 375 of file Array.nut.

◆ Create3D()

function _MinchinWeb_Array_::Create3D ( length ,
width ,
height  )
static

Creates a three dimensional (3-D) array.

Parameters
lengththe desired length of the array (in the first dimension)
widththe desired length of the array (in the second dimension)
heightthe desired length of the array (in the third dimension)
Returns
empty array of the given size (in three dimensions)
See also
Create1D()
Create2D()

Definition at line 384 of file Array.nut.

◆ Find1D()

function _MinchinWeb_Array_::Find1D ( InArray ,
SearchValue  )
static

Searches an array for a given value.

Parameters
InArrayarray to search (assumed to be two dimensional (2-D))
SearchArrayarray to search for (assumed to be one dimensional (1-D))
Returns
array index of the first time SearchValue is found (as an integer), false if not. null if InArray is null.
See also
ContainedIn1D()
Find2D()
Find3D()
FindPairs()
Note
using this to see if an given array is an element of the parent array does not seem to be returning expected results. Use FindPairs() instead.
Todo
Add error check that an array is provided

Definition at line 511 of file Array.nut.

◆ Find2D()

function _MinchinWeb_Array_::Find2D ( InArray ,
SearchValue  )
static

Searches an array for a given value.

Parameters
InArrayarray to search (assumed to be two dimensional (2-D))
SearchValuewhat is searched for
Returns
array index of the first time SearchValue is found (as an two dimensional array, of the from [i, j]), false if not. null if InArray is null.
See also
ContainedIn2D()
Find1D()
Find3D()
Todo
Add error check that an array is provided

Definition at line 524 of file Array.nut.

◆ Find3D()

function _MinchinWeb_Array_::Find3D ( InArray ,
SearchValue  )
static

Searches an array for a given value.

Parameters
InArrayarray to search (assumed to be three dimensional (3-D))
SearchValuewhat is searched for
Returns
array index of the first time SearchValue is found (as an three dimensional array, of the from [i, j, k]), false if not. null if InArray is null.
See also
ContainedIn3D()
Find1D()
Find2D()
Todo
Add error check that an array is provided

Definition at line 539 of file Array.nut.

◆ FindPairs()

function _MinchinWeb_Array_::FindPairs ( InArray2D ,
SearchValue1 ,
SearchValue2  )
static

Searches an array for a given pair of values.

The idea is to provide an array of arrays of pairs (e.g. tile x and tile y, starting and ending points, etc.), and find out if SearchValue1 and SearchValue2 are among the pairs. The order that SearchValue1 and SearchValue2 is not considered.

Parameters
InArray2Dtwo dimensional (2-D) array
SearchValue1values to search for
SearchValue2values to search for
Returns
index (as an integer) of the array matching the search values. null if InArray2D is null.
See also
ContainedInPairs()
Todo
Add error check that a 2D array is provided

Definition at line 644 of file Array.nut.

◆ InsertValueAt()

function _MinchinWeb_Array_::InsertValueAt ( InArray ,
Index ,
Value  )
static

Adds an element from the array.

Adds Value to the InArray at the given Index. The rest of the array is shifted one place to the right. The returned array is thus one longer than InArray.

Parameters
InArraythe array to add the element to
Indexthe index of where to add Value at
Valuethe element to add
Returns
InArray, now with the element Value at Index, the elements beyond it shifted to the right.
Todo

Add error check that an array is provided

Add error check that Index is reasonable

Definition at line 570 of file Array.nut.

◆ RemoveDuplicates()

function _MinchinWeb_Array_::RemoveDuplicates ( Array )
static

Removes duplicates from an array.

The item is maintain at its first location and removed at all subsequent locations.

Parameters
Arrayarray to remove duplicates from
Returns
An array minus the duplicate items.
Todo
Add error check that an array is provided.

Definition at line 719 of file Array.nut.

◆ RemoveValueAt()

function _MinchinWeb_Array_::RemoveValueAt ( InArray ,
Index  )
static

Removes an element from the array.

Removes the value at the index, and shifts the rest of the array to the left. The returned array is thus one shorter than the supplied array.

Parameters
InArraythe array to remove the element from
Indexthe index of the element to remove
Returns
InArray sans the element at Index, the elements beyond it are shifted to the left.
Todo
Add error check that an array is provided

Definition at line 556 of file Array.nut.

◆ ToAIList()

function _MinchinWeb_Array_::ToAIList ( Array )
static

Turns an Array in an AIList.

Returns
An AIList with the contents of the Array
Todo
Add error check that an array is provided.

Definition at line 732 of file Array.nut.

◆ ToString1D()

function _MinchinWeb_Array_::ToString1D ( InArray ,
DisplayLength = true,
replaceNull = false )
static

Converts a one dimensional array to a nice string format.

This function was created to aid in the output of arrays to the AI debug screen.

Parameters
InArrayone dimensional (1-D) array
DisplayLengthwhether to prefix the output with the length of the array
replaceNull(true or false) whether to replace null values with "-". Default is false. Note that the function will raise an error if set to false and a null value is encountered.
Returns
string version of array. e.g. The array is 3 long. 3 4 5.
null if InArray is null.
See also
ToString2D()
ToStringTiles1D()
Todo
Add error check that an array is provided

Definition at line 397 of file Array.nut.

◆ ToString2D()

function _MinchinWeb_Array_::ToString2D ( InArray ,
DisplayLength = true,
replaceNull = false )
static

Converts a two dimensional array to a nice string format.

This function was created to aid in the output of arrays to the AI debug screen.

Parameters
InArraytwo dimensional (2-D) array
DisplayLengthwhether to prefix the output with the length of the array
replaceNull(true or false) whether to replace null values with "-". Default is false. Note that the function will raise an error if set to false and a null value is encountered.
Returns
string version of array. e.g. The array is 2 long. 3 4 / 5 6.
null if InArray is null.
See also
ToString1D()
ToStringTiles2D()
Todo
Add error check that a 2D array is provided

Definition at line 419 of file Array.nut.

◆ ToStringTiles1D()

function _MinchinWeb_Array_::ToStringTiles1D ( InArrayOfTiles ,
ArrayLength = false,
replaceNull = false )
static

Converts a one dimensional array of tiles to a nice string format.

This function was created to aid in the output of arrays of tiles to the AI debug screen.

Parameters
InArrayOfTilesone dimensional (1-D) array of Tiles
ArrayLength(true or false) whether to print the prefix noting the length of the array. Default is false.
replaceNull(true or false) whether to replace null values with "---". Default is false. Note that the function will raise an error if set to false and a null value is encountered.
Returns
string version of array. e.g. The array is 3 long. 12,45 62,52 59,10.
null if InArrayOfTiles is null.
See also
ToString1D()
ToStringTiles2D()
Todo

Add error check that an array is provided

Add a better error message if you try and feed it not a 1-D array

Definition at line 584 of file Array.nut.

◆ ToStringTiles2D()

function _MinchinWeb_Array_::ToStringTiles2D ( InArrayOfTiles ,
ArrayLength = false,
replaceNull = false )
static

Converts a one dimensional array of tiles to a nice string format.

This function was created to aid in the output of arrays of tiles to the AI debug screen.

Parameters
InArrayOfTilestwo dimensional (2-D) array of Tiles
ArrayLength(true or false) whether to print the prefix noting the length of the array. Default is false.
replaceNull(true or false) whether to replace null values with "---". Default is false. Note that the function will raise an error if set to false and a null value is encountered.
Returns
string version of array. e.g. The array is 2 long. 12,45 62,52 / 59,10 5,37.
null if InArrayOfTiles is null.
See also
ToString2D()
ToStringTiles1D()
Todo

Add error check that an array is provided

Add a better error message if you try and feed it not a 2-D array

Definition at line 607 of file Array.nut.

Member Data Documentation

◆ main

_MinchinWeb_Array_::main = null
private

Definition at line 31 of file Array.nut.


The documentation for this class was generated from the following file: