Log in

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

Start(mode)

This function has one numerical argument. If bit 0 is set script should import regular prices, if bit 1 is set script should import foil prices (if both bits are set script should import both). Example:

function Start(mode)
   if mode ~= 2 then
      -- Import regular prices
   end
   if mode ~= 1 then
      -- Import foil prices
   end
end

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 like
ma.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.)

Log

ma.Log(message)

Adds debug message to Magic Album log file.

SetPrice

ma.SetPrice(setid, langabbr, cardname, cardversion, regprice, foilprice)

Set the price of the certain card.

  • setid is the numeric ID of the card. You can find all available IDs in "Database\Sets.csv" file.
  • langabbr is 3 letters language abbreviation (i.e. ENG, RUS, GER).
  • 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.

Examples:

-- Set the price of foil M11 English Celestial Purge to $4.25
ma.SetPrice(770, "ENG", "Celestial Purge", "", 0, 4.25)
-- Set the regular and foil prices for all versions of M10 Russian Forests
ma.SetPrice(759, "RUS", "Forest", "*", 0.01, 0.1)

SetPBar

ma.SetPBar(text, position)

Sets progress bar text and position. Position is a numeric value in range 0..100.