Editing
Module
:
MiscData
Give feedback
Jump to navigation
Jump to search
Warning:
You are not logged in. Once you make an edit, a temporary account will be created for you.
Learn more
.
Log in
or
create an account
to continue receiving notifications after this account expires, and to access other features.
Anti-spam check. Do
not
fill this in!
local p = {} -- Load data and utility modules local misc_data = mw.loadJsonData("Data:MiscData.json") local util_module = require('Module:Utilities') -- returns the entire data table for Misc data, used by other Lua modules function p.get_misc_data(name) if not name or name == '' then return nil end return misc_data[name] end -- Retrieves a specific stat value for Misc. Handles both simple and nested calls. -- {{#invoke:MiscData|get_misc_var|MISC_KEY|STAT_KEY_1|STAT_KEY_2|...|SIG_FIGS}} p.get_misc_var = function(frame) -- Safer argument handling for both live and debug environments local args = {} if frame.getParent then local parent_args = frame:getParent().args for k, v in pairs(parent_args) do args[k] = v end end -- Direct args from #invoke or the debug table overwrite parent args for k, v in pairs(frame.args) do args[k] = v end local misc_name = args[1] and mw.text.trim(args[1]) or nil if not misc_name or misc_name == '' then return '<span class="error">Error: Misc name not provided.</span>' end local misc = misc_data[misc_name] if not misc then return '<span class="error">Error: misc "' .. misc_name .. '" not found.</span>' end local current_value = misc local last_key_index = 1 local path = {misc_name} -- Track the path for better error messages -- Traverse through the arguments to find the nested value for i = 2, #args do local key = args[i] and mw.text.trim(args[i]) or nil if not key or key == '' then break end -- Check if this might be the sig_figs argument (numeric on a non-table) if tonumber(key) and type(current_value) ~= "table" then break end if type(current_value) ~= "table" then return '<span class="error">Error: Invalid path at "' .. table.concat(path, '.') .. '". Tried to index a ' .. type(current_value) .. ' value.</span>' end -- Try string key first local next_value = current_value[key] -- If nil, try numeric key if next_value == nil then local num_key = tonumber(key) if num_key then next_value = current_value[num_key] end end if next_value == nil then return '<span class="error">Error: Key "' .. key .. '" not found in path "' .. table.concat(path, '.') .. '".</span>' end current_value = next_value table.insert(path, key) last_key_index = i end -- Handle sig_figs if provided local sig_figs_arg = args[last_key_index + 1] local sig_figs = sig_figs_arg and tonumber(mw.text.trim(sig_figs_arg)) or nil if sig_figs then if type(current_value) ~= "number" then return '<span class="error">Error: Cannot apply sig_figs to non-numeric value at "' .. table.concat(path, '.') .. '" (type: ' .. type(current_value) .. ').</span>' end current_value = util_module.round_to_sig_fig(current_value, sig_figs) if current_value == nil then return '<span class="error">Error: Rounding failed for value at "' .. table.concat(path, '.') .. '".</span>' end end -- Convert tables/booleans to strings for display if type(current_value) == "table" then return '<span class="error">Error: Path "' .. table.concat(path, '.') .. '" points to a table/object. Specify a deeper path to get a value.</span>' elseif type(current_value) == "boolean" then return tostring(current_value) end return current_value end return p
Summary:
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Deadlock:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Pages included on this page:
Template:Tl
(
edit
)
Module:MiscData
(
edit
)
Module:MiscData/doc
(
edit
)
Module:Utilities
(
edit
)
Data:MiscData.json
(
view source
) (⧼restriction-level-bot+⧽)
Navigation menu
Personal tools
Create account
Log in
associated-pages
Module
Discussion
English
Views
Read
Edit source
History
Tools
Search
Discord
Discord
Navigation
Main page
About us
Random page
Special pages
Recent changes
Unstable Rift
4h ago
·
~2026-IvyGankStone1157
Haze/Sounds
5h ago
·
Gammaton32
Haze/Voice lines
5h ago
·
Gammaton32
Grey Talon/Voice lines
5h ago
·
Gammaton32
Show more...
Interface Admin
Common CSS
Vector CSS
Minerva CSS
Citizen CSS
Brown theme CSS
Gadgets
Gadgets definition
Editing
How to edit
Style guide
All guides
New files
Unresolved feedback
Tools
What links here
Related changes
Page information