Module:AnimalData/doc: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
Demian (talk | contribs)
m Update links.
Demian (talk | contribs)
m Add to category "Eco data files".
Line 24: Line 24:
end
end
</syntaxhighlight>
</syntaxhighlight>
<includeonly>[[Category:Eco data files]]</includeonly>

Revision as of 11:43, 26 February 2022

Documentation

Template:Data file module

The data file is currently used in at least the following modules:

Usage

-- Load data only once per page. (Do no use require())
local AnimalData = mw.loadData("Module:AnimalData")

-- Assert that some data was received, otherwise throw an error.
assert(AnimalData.animals, "Failed to load data from Module:AnimalData!")

-- You may then use data from this module in your script. For example:
local agoutiData = AnimalData.animals["Agouti"]

-- Or to iterate over the table, you can do this:
for animalName, data in pairs(AnimalData.animals) do
	-- animalName now contains the name of the animal in English.
	-- data is the data table for that animal.
end