Magic Album Lua API
Contents |
Introduction
Magic Album uses Lua as an embedded scripting language. You can write your own scripts to import card prices from your favorite online shops. If you do not familiar with the Lua start with reading the official documentation.
Price Scripts
Scripts responsible for price importing should be placed in "Prices" directory and had ".lua" extension. You should restart Magic Album if you delete or add scripts to this directory (application restart is not needed if you modify the content of the scripts). Every price script must include startup function
function ImportPrice(importfoil, importlangs, importsets)
- importfoil: "Y" - if the script should import both foils and regulars, "N" - if the script should import only regulars, "O" - if the script should import only foils.
- importlangs: array of languages script should import, represented as pairs {languageid, languagename} (see "Database\Languages.txt" file).
- importsets: array of sets script should import, represented as pairs {setid, setname} (see "Database\Sets.txt" file).
API Functions
Magic Album provides several functions you can use in Lua scripts. These functions are grouped under "ma" table so the call will look likema.funcname(arg1, arg2, ... argn)
GetURL
webpage = ma.GetURL(url)
Returns downloaded web page or nil if there was an error (page not found, network problems, etc.)
GetFile
file = ma.GetFile(filepath)
file = ma.GetFile("Prices\\test.dat")
Log
ma.Log(message)
Adds debug message to Magic Album log file.
SetPrice
modifiednum = ma.SetPrice(setid, langid, cardname, cardversion, regprice, foilprice)
Set the price of the certain card.
- setid is the numeric ID of the set. You can find all available IDs in "Database\Sets.txt" file.
- langid is the numeric ID of the language. You can find all available IDs in "Database\Languages.txt" file.
- cardname is the name of the card
- cardversion is the version of the card as it is shown in Magic Album. If set to "*" all versions of the card will be processed.
- regprice and foilprice are the numerical values. Pass zero if you do not know or do not want to set the value.
- this function returns the number of modified cards.
Examples:
-- Set the price of foil M11 English Celestial Purge to $4.25 ma.SetPrice(770, 1, "Celestial Purge", "", 0, 4.25) -- Set the regular and foil prices for all versions of M10 Russian Forests ma.SetPrice(759, 2, "Forest", "*", 0.01, 0.1)
SetProgress
ma.SetProgress(text, position)
Sets progress bar text and position. Position is a numeric value in range 0..100.
Example
File "Prices\MTG Mint Card.lua" is a working script example. Start with understanding it before writing your own scripts.
