GM Database Support v3.1.1 by Alasdair Forsythe (www.gmdatabase.co.uk)

Advanced: Array Scripts

This set of scripts is of very useful scripts that enable you to load a table from a database file and store it in a 2 dimensional array. Once a table has been copied into an array searches can be performed on it with much greater speed, although if the table is large then it may use up a lot of memory.

Remember that if you're not using encryption then you'll need to add a blank script called 'encryption' anyway.

To import these scripts into your game select 'Import Scripts' from the Game Maker 'File' menu and then locate the 'Database: Array' script file. You should delete any scripts that you're not using so as the game will load faster.

To call the scripts use the format as shown below. You can call a script at any time during the game.
Eg. to set the variable jeff to the value of the 4th column, 3rd row, in the 1st table of database file data.txt use:

jeff=lookup_direct('data.txt',1,4,3)

On the overviews of the scripts below the format shows you what to put in each argument.

Argument types is the type of argument required: string, real or adv.
Adv means it uses the advanced search which just means that:

- If you put in a number (real) above 0 then the script will jump to this value along (this is fastest).
- If you put in a string then the script will go to the first table/column/row with this name.
- If you enter -1 then the names of the table/column/row will be executed as code to check if they're true and it goes to the first one that's true.
- If you enter -2 it checks to see if they're false.

If any of the scripts fail they return -1.

array_table
array_search
insert_array

array_table:
format: array_table(file_name,z,var,write)
argument types: array_table(string,adv,string,true/false)
This script either puts a table into a 2D array or puts it back into a database.

- file_name is the path or filename of the database file.
- z is the position of the table you wish to extract/put back, eg. 4 would mean the forth table. When putting tables back into the database file this table is overwritten, you can use this to duplicate tables.
- var is the variable that it'll be put into/taken out of. The variable it's put into with x and y and the end contain the total x and y, eg. if var was 'bob' then 'bobx' would contain the total cols and 'boby' would contain the total rows. The names of the rows and columns are put into the 0 indexes and [0,0] contains the name of the table. See database format for more information.
- write is if to write it to the file or pull it out. True/1=write it to the file, false/0=extract it from the file.

array_search:
format: array_search(array_name,x,y,change_to)
argument types: array_search(string,adv,adv,string)
This script is similar to lookup_direct except it's used for arrays that have been created with the array_table script.
There's no point using this script if you're only putting numbers for both x and y, eg. if you want x3, y5 in the variable 'bob' it's located at bob[3,5]. This script is so you can perform the advanced searching methods on tables that have been loaded into arrays.

- array_name is the name of the variable to search in (as a string).
- x is the column position in that table.
- y is the row position in that table.
- change_to is the new value you wish to put in the cell. If a string is put in change_to then the cell is changed to this string. If a real is put in change_to or no value at all then the script just returns the value of the z, x, y cell.

insert_array:
format: insert_array(array_name,pos,col/row,ins/del)
argument types: insert_array(string,real,true/false,true/false)

This script is similar to insert_direct except it's used for arrays.

- array_name is the name of the variable to search in (as a string).
- pos is the position along to insert/delete the row/column, eg. 2 would mean the second row/column. 0 is the last column/row.
- row/col means whether it's a row or a column you're wanting to create/delete. True/1=column, false/0=row.
- ins/del is if you want to insert a new row/column here or delete the current one. True/1=insert, false/0=delete.