Skip to content

foonly/randomtable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RandomTable Parser Class

A parser class for randomizing tables

This parser uses a format developed by Dr. J.M. "Thijs" Krijger matthijs.krijger@gmail.com. The parser class and documentation is written by Niklas Schönberg niko@uplink.fi and released under the GPL.

Usage

The class is used with a text string containing the tables (see format.md). The string can be given as the first argument in the constructor, and/or with the populate() method.

A result can then be generated by using the generate() method. This returns the generated result as a string.

The Methods

__construct([rawData=null[,dataSetName=null]])

The rawData is the table definition you wish to use. It's optional, but must be given at some point before generate() can be used. dataSetName is an optional name given for the data set, this is used with include instructions so that the parser can keep track of which data sets you have included.

populate(rawData[,dataSetName=null[,reset=false]])

This works in very much the same way as the constructor for rawData and dataSetName. The additional reset attribute is used to empty all previously included data sets and start from scratch.

getInclude()

Returns an array containing all records currently in the include stack. The stack is populated by "@dataSetName" instructions in a data set.

popInclude()

Returns one record from the include stack, and removes it from the stack.

isLoaded(dataSetName)

Checks to see if a data set is loaded. Returns true or false. This (and most other include methods) only works as long as you provide the names of the data sets when you load them.

generate([tableName=null[,keepSet=false]])

Generates and returns a string based on the loaded data set(s). If tableName is defined, that is the initial table. If not, the default table will be used. If keepSet is true, the set data will not be discarded. This means that items from sets can not repeat from the previous call. Variable data is always discarded.

getVar(variableName)

Reads the value of a variable defined by the data set.

setVar(variableName,value)

Writes a value into a variable. Note that any variable data will be discarded on generate() call, so this is only useful if you read the data with getVar().

getStatement()

Returns the currently active statement. This is basically just instructions on how to parse the data set.

setStatement(value[,overwrite=false])

Sets an active statement. Includes, "@dataSetName", are added to the include stack and removed from the active statement. If overwrite is false the statement is not written if not empty.

About

A parser class for randomizing tables

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages