Difference between revisions of "Module:Sandbox"
From Nookipedia, the Animal Crossing wiki
PanchamBro (talk | contribs) (restructuring module: now should catch instances where a particular name should be lowercased) |
PanchamBro (talk | contribs) |
||
Line 1: | Line 1: | ||
+ | -- Generates random New Horizons item name; adopted from Temtem Wiki, licensed under CC BY-NC-SA, authors listed here: https://temtem.wiki.gg/wiki/Module:Daily_tem?action=history | ||
local p = {} | local p = {} | ||
− | local | + | local cargo = mw.ext.cargo |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
function p.main(frame) | function p.main(frame) | ||
− | + | local tables = 'nh_furniture' | |
− | local | + | local count = cargo.query( tables, 'COUNT(DISTINCT en_name)=n', {'no html'})[1]['n'] |
− | + | ||
− | + | math.randomseed(os.date("%Y%m%d")) | |
− | |||
− | + | local args = { | |
− | + | limit = 1, | |
− | + | offset = math.floor(math.random() * count), | |
− | + | } | |
− | + | local results = cargo.query( tables, 'en_name', args ) | |
− | + | local name = results[1]['name'] | |
− | + | ||
− | + | return name | |
− | |||
− | |||
− | |||
− | return | ||
end | end | ||
return p | return p |
Revision as of 00:55, December 2, 2022
Module documentation (view)
Usage
This is the general sandbox page to test out Lua modules. The module should not be implemented in a template.
-- Generates random New Horizons item name; adopted from Temtem Wiki, licensed under CC BY-NC-SA, authors listed here: https://temtem.wiki.gg/wiki/Module:Daily_tem?action=history
local p = {}
local cargo = mw.ext.cargo
function p.main(frame)
local tables = 'nh_furniture'
local count = cargo.query( tables, 'COUNT(DISTINCT en_name)=n', {'no html'})[1]['n']
math.randomseed(os.date("%Y%m%d"))
local args = {
limit = 1,
offset = math.floor(math.random() * count),
}
local results = cargo.query( tables, 'en_name', args )
local name = results[1]['name']
return name
end
return p