[unchecked revision] | [unchecked revision] |
m →Documentation: Use Wiki Discord server template. |
m Use new "Data file module" template. |
||
Line 1: | Line 1: | ||
== Documentation == | == Documentation == | ||
{{ | {{Data file module}} | ||
The data file is currently used in at least the following modules: | The data file is currently used in at least the following modules: | ||
Line 9: | Line 7: | ||
* [[Module:List_Fish]]: see [[Template:FishList]] for more details. | * [[Module:List_Fish]]: see [[Template:FishList]] for more details. | ||
== Usage == | |||
<syntaxhighlight lang="lua"> | |||
-- Load data only once per page. (Do no use require()) | -- Load data only once per page. (Do no use require()) | ||
local AnimalData = mw.loadData("Module:AnimalData") | local AnimalData = mw.loadData("Module:AnimalData") |
Revision as of 22:59, 24 February 2022
Documentation
The data file is currently used in at least the following modules:
- Module:Infobox_Animal: see Template:Infobox_Animal for more details.
- Module:List_Animals: see Template:AnimalList for more details.
- Module:List_Fish: see Template:FishList for more details.
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