Module:Sandbox/LVL: Difference between revisions

LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 26: Line 26:
--[[
--[[
Retrieves a specific stat value for a given NPC.
Retrieves a specific stat value for a given NPC.
Usage: {{#invoke:NpcData|get_npc_var|NPC_NAME|STAT_NAME|sig_figs_or_localize}}
Usage: {{#invoke:LVL/Sandbox|get_npc_var|NPC_NAME|STAT_NAME|sig_figs_or_localize}}
- NPC_NAME: The key of the NPC (e.g., "npc_boss_tier2").
- NPC_NAME: The key of the NPC (e.g., "npc_boss_tier2").
- STAT_NAME: The name of the stat (e.g., "MaxHealth").
- STAT_NAME: The name of the stat (e.g., "MaxHealth").
Line 35: Line 35:
p.get_npc_var = function(frame)
p.get_npc_var = function(frame)
-- Get arguments from the #invoke call and trim whitespace
-- Get arguments from the #invoke call and trim whitespace
local npc_name = frame.args[1] and mw.text.trim(frame.args[1]) or nil
local args = frame.args
local npc_stat_key = frame.args[2] and mw.text.trim(frame.args[2]) or nil
local npc_name = args[1] and mw.text.trim(args[1]) or nil
local sig_figs_or_localize = frame.args[3] and mw.text.trim(frame.args[3]) or nil
local npc_stat_key = args[2] and mw.text.trim(args[2]) or nil
local sig_figs_or_localize = args[3] and mw.text.trim(args[3]) or nil


-- Validate required arguments
-- Validate required arguments
Line 56: Line 57:
local var_value = npc[npc_stat_key]
local var_value = npc[npc_stat_key]
if var_value == nil then
if var_value == nil then
return 0 -- Mimics HeroData behavior for non-existent stats
-- Always return a visible error if the stat is not found.
return '<span class="error">Error: Stat "' .. npc_stat_key .. '" not found for NPC "' .. npc_name .. '".</span>'
end
end