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

Advanced: Basic Scripts

These are the most basic database scripts that you will most likely be using.

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: Basic' 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.

lookup_direct
insert_direct
ins_table_direct
database_info

lookup_direct:
format: lookup_direct(file_name,z,x,y,change_to)
argument types: lookup_direct(string,adv,adv,adv,string)
This script is the most important one of all, it enables you to check a database directly (from the file) and return/change the value of any cell in that database.

- file_name is the path or filename of the database file.
- z is the table position in the file.
- 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. This must be a string or the value of that cell is returned.

0 can be entered for x/y to make it check for the name of that row/col (see last section). If 0 is put for both x and y then it'll return the name of that table.
The value returned is always a string.

insert_direct:
format: insert_direct(file_name,z,pos,col/row,ins/del)
argument types: insert_direct(string,adv,real,true/false,true/false)
This script inserts/deletes columns/rows in a certain table of a database file.

- file_name is the path or filename of the database file.
- z is the table position in the file.
- pos is the position along to insert/delete the row/column, eg. 2 would mean the second row/column. If 0 is entered it takes this as the last position (useful for adding a column/row at the end).
- col/row means whether it's a row or a column you're wanting to insert/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.

You'll need to use the lookup_direct script to change the value of the cells in a new column/row.

ins_table_direct:
format: ins_table_direct(file_name,pos,ins/del/clr,cols,rows)
argument types: ins_table_direct(string,adv,0/1/2,real,real)

This script inserts a blank cols*rows table at position pos, you'll need to edit the cells.

- file_name is the path or filename of the database file.
- pos is the position along to insert/delete the table at, eg. 3 would mean the third table.
- ins/del/clr is if to insert, delete or clear this table. 1=create, 0=delete, 2=clear.
- cols is how many columns to create in this new table. This argument isn't used if you're deleting the table.
- rows is how many rows to create in this new table. This argument isn't used if you're deleting the table.

database_info:
format: database_info(file_name,z,x,y)
argument types: database_info(string,real,real,real)

This script returns a certain piece of information about the database file. It always returns a real value.

- database_info('data.txt',0,0,0) is whether the database file is encrypted of not (true/false).
- database_info('data.txt',1,0,0) is how many tables in the database file.
- database_info('data.txt',2,1,0) is how many columns in table 2.
- database_info('data.txt',4,0,1) is how many rows in table 4.