Skip to content

Accessing & Viewing

nnnik edited this page Aug 16, 2018 · 1 revision

This section describes functionality for viewing and accessing the content of the matrix using native AHK. This functionality is for debugging and checking if your results match your expectations. Most of it is incredibly slow.

Turning your matrix into a string

str := newMat.toString([fn])

This will turn a matrixs contents into a string for display purposes.

  • newMat: The matrix that will be turned into a string
  • str: The resulting string
  • fn: An optional change function

This method will turn the values into a string that can be shown on the screen - e.g. a Msgbox. The string format might change though - so do not use this for saving/loading.

The fn parameter allows you to define a function that will change the output of this method. If you define fn, the toString method will call this function for each value inside the matrix and then appends the output of that function to the resulting string. There are many ways to define which function you want to use. The toString method works with function names, func objects, boundfuncs, closures, nested functions and generally every object that handles the call method correctly.

Error detection could probably be enhanced.

Getting and setting the contents of a Matrix

value := newMat.values[x, y] ;getting a value
newMat.values[x, y] := value ;setting a value 

This will get or set a single value of the matrix contents.

  • newMat: The matrix that you want to change/read from
  • value: The value that you want to set
  • x: The column index of the value you want to change
  • y: The row index of the value you want to change

value needs to be a valid integer or floating point number or the action might fail and it might throw an error.

x and y need to be positive integers. Both values are 1 indexed - like all arrays in AHK. That means that the 1st row/column has the index 1. The first value inside the entire matrix contents is newMat.values[1, 1]

All following usages of the values property are essentially just wrappers around this usage. They are therefore slower and have more overhead than using this. They also have the same limitations and properties as this.


column := newMat.values[x] ;getting a column 
newMat.values[x] := column ;setting a column

This sets or gets an entire column, of the matrix contents, as array.

  • newMat: The matrix that you want to read from or write to.
  • column: the values of the column - a numerical array containing multiple values.
  • x: The index of the column

column is an array that starts at 1 and is as long as the matrix high is. There is an entry for every integer value between 1 and the matrix height. There are no other values in this array.

Thats what you can expect from the output of the values property and is also what the values property expects as input. If a column you pass to this property does not meet these expectations the property may fail.

x is just like the x from the usage before.


row := newMat.values["", y]
newMat.values["", y] := row

This will set or get an entire row of the matrix contents.

  • newMat: The matrix that you want to read from or write to.
  • row: the values of the row - a numerical array containing multiple values.
  • y: The index of the row

row is an array that starts at 1 and is as long as the matrix wide is. There is an entry for every integer value between 1 and the matrix width. There are no other values in this array.

Thats what you can expect from the output of the values property and is also what the values property expects as input. If a row is passed, that does not meet these criterias, the property may fail.

y is just like y from the first values property usage above.

This is used by the following.


rows := newMat.values
newMat.values := rows

This will get or set the entire matrix contents.

  • newMat: The matrix that you want to set or get.
  • rows: The contents of the matrix as an array of rows and rows as an array of values

rows is an array that contains multiple rows. It is as long as the matrix high is. There is a row for every entry between 1 and the height of the matrix. There are no other entries in the array.

Each row is just like the row mentioned above.

Thats what you can expect from the output of the values property and is also what the values property expects as input. If a rows array is passed, that does not meet these criterias, the values property may fail.