SUINEVERE   Sega Saturn Hacks and Homebrew

SATURN LINK : MIDGAARD   MQL
Guides » Running the world » Archon help » M » MQL
MQL
MQL Stands for MUD Query Language.  It's purpose is to allow the Archon, or a random quest xml document, to select existing objects in the game, or the properties of existing objects.  

The structure of MQL is similar to SQL in that all MQL statements are of this structure:

SELECT: [property, property, ..] FROM [object set]  WHERE [object comparison (logic) object comparison]
* note the colon : after the word SELECT above.
UPDATE: [object set] SET [property=value, ...] WHERE [object comparison (logic) object comparison]
DELETE: from [object set] WHERE [object comparison (logic) object comparison]
* note the colon : after the words SELECT, UPDATE, DELETE above.

The SELECT clause defines the properties you wish to be returned from the MQL statement.
The FROM clause defines the set of objects that you might want to return the properties of.
The WHERE clause defines the conditions under which any member of the set in the FROM clause may be included in the final results.

A FROM clause can be a simple world set term, such as one of the following:

* A CMFS file path to a CMARE file, such as ::/resources/map/plains.cmare
* AREAS to use the set of all world areas
* ROOMS to use the set of all existing world rooms
* NPROOMS to use the set of non-property (Prop_RoomForSale) rooms.
* ORPHROOMS to use the set of rooms without a link into them.
* MOBS to use the set of all existing world mobs and player mobs
* NPCS to use the set of all existing world npc mobs
* ITEMS to use the set of all existing world items
* PLAYERS to use the set of player mobs.
* RESOURCES to use the set of resource items.
* FACTIONS to use the set of game factions.
* RACES to use the set of game races.
* SHOPS to use the set of shopkeepers.
* TAGGED to use things tagged by the NEXT narrowing suffix
* In case where a qualifying object is implied, AREA can be used to refer to that specific area.
* Another SELECT: statement in parenthesis, such as: SELECT: name from (SELECT * from AREA)

The FROM clause can also include narrowing suffixes.  A narrowing suffix comes after the simple term, and is separated from it by a backslash \.   For example, if your from clause looks like SELECT * FROM AREAS\ROOM  , then the ROOM portion is the narrowing suffix of the AREAS term.  You can also continue adding more narrowing suffixes as needed.  For example: SELECT * FROM AREAS\MOBS\EQUIPMENT  .  Each suffix narrows or alters the term immediate before it, and the entire FROM clause will end up reflecting the type of object described by the final term, whether it be simple, or a narrowing term.

The following are useful narrowing terms:

* AREAS to use the unique set of areas in which the prior term is located
* AREA to refer to the area where the prior term is located
* ROOMS to use the unique set of rooms in which the prior term is located, or which the prior term contains
* ROOM to use the room in which the prior term is located.
* MOBS, MOB to use the set of all mobs contained in the prior term
* ITEMS, ITEM to use the set of all items contained in the prior term
* OWNER to use the set of all item owners of the prior term, if it was items
* EQUIPMENT to use the set of all  worn items of the prior term
* SHOPITEMS to use the set of shopkeeper items
* EXITS to use the set of applicable exits
* PLAYER to use the player npc applicable
* MOB to use the mob object applicable
* GROUP to use the group members of the mob object applicable
* NPCS, NPC to use the npc mob objects applicable
* ITEM to use the item object applicable
* EQUIPMENT to use the equipment item applicable
* OWNER to use the item owner object for a prior item term
* FACTIONS for the set of applicable factions
* RESOURCES for racial or material components that apply
* ABILITIES to use the list of abilities for the prior term
* PROPERTIES to use the list of Property effects for the prior term
* EFFECTS to use the list of effects for the prior term
* BEHAVIORS to use the list of behaviors for the prior term
* SHOP to use the shop object for the prior term

Be careful when using narrowing terms to make sure they make sense for the term prior to them.  For example, if importing mobs from a cmare file, AREAS will not likely resolve to anything, since the mobs aren't in the world yet.

The SELECT: clause can include one or more comma-delimited properties of  the objects in the from clause, or it can be an asterisk *, or a period ., to refer simply to the from objects themselves.  It can also be a string or numeric literal, or an XML tag when embedding MQL in a random quest document.    Different kinds of objects have different kinds of properties, so it is tricky to define precisely what a legal and illegal object property might be.  Choosing incorrectly will usually just result in an empty string "".

An example of a legal property might be the property CLASS, since it applies to everything from areas and rooms, to mobs, and items.  NAME is also a property that almost all objects have.  Beyond this. using the GMODIFY command might be the simplest way to get a list of valid properties for a specific type of world object, or objects imported from cmare files.

As mentioned previously, SELECT: clause properties can be separated by commas in order to select more than one.  For example: SELECT: class, name FROM areas\mobs would show the class id and name of every mob in your game.

SELECT: clauses can also include an AS qualifier for each property selected.  This has only the effect of changing the apparent name of the property for other parts of the system.  For an example using the WHERE command to issue MQL: WHERE AREA SELECT: class as classid, name as mob_name FROM areas\mobs would show the same results as the previous example statement, but with different name tags for the class and name properties.  This might be important when using an embedded SELECT: statement as your FROM clause, since you can only select properties that the embedded clause has returned, by the names they were given.

SELECT: clauses, similar to FROM clauses above, can include narrowing terms.  Like FROM clauses, these narrowing terms are separated by backslashes \.   SELECT clauses, at the moment, only support one narrowing term: COUNT.  The purpose of the COUNT term is to report the number of times the value of the previous terms appears in the rest of the FROM: clause.  For example, suppose you wanted to know the number of times each mob name is used, to do that, you might enter SELECT: name, name\count FROM areas\mobs

Lastly, SELECT: clause can contain aggregating prefixes before a property term, which will transform the final result set in some way by aggregating the rows according to the prefix.  Prefixes, like suffixes, are separated from the property term by a backslash \.  The value aggregating prefixes are:

* MEDIAN to return only the median value of all the property terms in the existing result set
* MEAN to return the mean value of all the property terms in the existing result set
* COUNT to return the count of the number of  items in the result set
* UNIQUE to include only one row where the property is of any given value
* FIRST to include only the first row
* ANY to include only a random row

For example, to quickly count the mobs in your game, you might enter SELECT: COUNT\* from AREAS\MOBS

The WHERE clause contains one or more conditions, which you can further compare using connectors like AND, OR, or parenthesis to group conditions together.  Each condition consists of  two terms separated by a comparator.  Value comparitors include = (equal to), <> (not equal to), > (greater than), < (less than), >= (greater or equal), <= (less or equal), IN (in a set or object group, or a substring of), or LIKE (matching a ZAPPERMASK).

A condition consists of two property terms, similar to those described in the SELECT: clause above, except that condition terms can not use aggregating prefixes.  Narrowing suffixes, however, are permitted.  For example NAME = 'Bob' is checking whether the NAME property of an item in the FROM clause is equal to the string literal "BOB".  If it is, when that condition is true.  Putting it together then, to show the mobs in your game whose names are EXACTLY "BOB", you might do SELECT: * FROM areas\mobs WHERE name="BOB". This works because NAME is a property of every mob in the AREAS\MOBS from set, and can be compared with the word "BOB".

Condition statements are grouped together into conditions using AND or OR.  For example, changing the above condition to WHERE name="BOB" OR name="JOE" would expand the number of possible results by one name.
[guides] [handbook] [races] [classes] [world] [levels] [help] [search] [home] [play]