Setting View Filters

To filter records in a view, use the #FIND or #QUERY commands. The #FIND command, by default, searches the first column of the view for records that contain the first argument. So,

#FIND sword

will display all of the records that have the word "sword" somewhere in the first column of the view. If the first column is a number field, the number must match the #FIND argument exactly. The optional second argument specifies the View and Database to be searched. By default the current view is used. You can specify a view name, or a string list with the view name as the first item, and the database name as the second item. So:

#FIND blue Potions

will display all of the records in the Potions view whose first column contains the string "blue". In other words, it pretty much does what it says...finds the blue potions. This makes the #FIND command a natural selection to query the database from the command line.

The optional third argument specifies the column to search instead of the first column. So,

#FIND str Weapons Comment

will search the Comment field for the string "str" and display the results from the Weapons view.

Normally the results of the #FIND command are both updated in the specified view, and also displayed to the MUD window. To prevent the display output to the MUD window, set the optional fourth argument to a non-zero value.

The #QUERY command is similar to the #FIND command, but instead of searching a given column for a particular string or number, you can specify a general query formula. You use the &FieldName syntax to refer to fields in the database, and form a normal zMUD expression that returns true for the records you want to display. For example

#VAR Level 20
#QUERY (&Level=@Level)

will display all of the records in the current view that have the Level field equal to 20 (the value of the @Level variable).

The optional second argument of #QUERY is the View|Database to use instead of the current view, and the optional third argument is non-zero to prevent the display of the results to the MUD output window.

The %query function is similar to the #QUERY command, and the %find function is similar to the #FIND command. The difference is that instead of displaying the results to the screen, they return a string list of the record numbers that match the filters. So, if the two blue potions in the Equipment Database are records 8 and 21, %find("blue","Potions") will return 8eq|20eq. You can then #FORALL over the results to manipulate each record.

#FORALL %find(Blue,Potions) {#SHOW &Name}

will display the Name field of each blue potion in the database.

To undo any #FIND and #QUERY command and return the view to its original state, use the #DBRESET command. The current record is also reset to the first record of the view. The optional second argument of the #DBRESET command is the name of the View|Database to reset.



Contents Using Database Views Accessing Records in a View