Module:Reward/doc

Lua metamodule which provides functions to work with reward definitions, such as Module:RewardText.

Functions

 * normalize (reward)
 * Normalizes a reward object, and returns it. If an error occurs, returns  plus an error message. Specifically, this function
 * ensures that  is an item or a list of items;
 * replaces  with a singleton array if the object itself represents a single item;
 * adds  and   properties to each item in the reward definition. (The   here is not the same as the Kind field in the Cargo reward tables.)
 * In general, all valid ObjectArg strings compatible with Module:RewardText produce normalized reward objects; ObjectArg sub-objects and reward objects directly constructed in Lua have to be normalized before they can be used in other functions.


 * parse (objstr)
 * If  is not a Lua table, parses it as a string using Module:ObjectArg and then returns a normalized reward object, or   plus an error message. If   is a Lua table, simply returns it unchanged.


 * define (reward, subtemplate, opts = {}, frame = nil)
 * Accepts a normalized reward object and stores it into an appropriate Cargo table, by expanding the reward definition template with the subpage name equal to . If   is given, it should be a Lua table containing extra template arguments (including from and to) to be applied to every reward item.   should be a Scribunto frame object, and the function will automatically pick up the current frame if it is not provided.


 * compare (x, y)
 * Compares two normalized reward objects.
 * If  and   represent identical rewards, returns.
 * If  is a better reward than , i.e.   contains all items in   plus other extra items, returns.
 * If  is a better reward than , returns.
 * If  is not better than   and   is not better than , i.e. each reward object contains items not found in the other one, returns.


 * best (t)
 * Given a Lua sequence of normalized reward objects, returns the unique best reward as determined by compare, or  if more than one best reward exists.