Module:Sandbox/LVL: Difference between revisionsGive feedback
Jump to navigation
Jump to search
No edit summary |
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: | 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 | local args = frame.args | ||
local npc_stat_key = | local npc_name = args[1] and mw.text.trim(args[1]) or nil | ||
local sig_figs_or_localize = | 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 | ||
-- 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 | ||