| [unchecked revision] | [checked revision] |
No edit summary |
|||
| (9 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{{DataModule}} | |||
== Usage == | |||
<syntaxhighlight lang="lua"> | |||
-- 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 | |||
</syntaxhighlight> | |||
Latest revision as of 11:45, 16 April 2026
ATTENTION! Data files are generated using game data and are not intended for manual editing.
Warning about use
[edit source]To prevent multiple call of data array, you must use the function: local AnimalData = mw.loadData("Module:AnimalData/doc")
Usage
[edit source]-- 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