Module:ItemTables: Difference between revisionsGive feedback
Jump to navigation
Jump to search
check if modules can also be in json |
test formatting |
||
| Line 12: | Line 12: | ||
return nil | return nil | ||
end | end | ||
-- Adds commas delimiter to the thousands place | |||
function Format(amount) | |||
local formatted = amount | |||
while true do | |||
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') | |||
if (k == 0) then | |||
break | |||
end | |||
end | |||
return formatted | |||
end | |||
--{{#invoke:Sandbox/Sylphoid|get_prop|ITEM_NAME|PROPERTY}}-- | --{{#invoke:Sandbox/Sylphoid|get_prop|ITEM_NAME|PROPERTY}}-- | ||
| Line 31: | Line 45: | ||
--return tableValues[property] | --return tableValues[property] | ||
end | end | ||
--{{#invoke:ItemData|get_cost|ITEM_NAME}}-- | |||
p.get_cost = function(frame) | |||
local item_name = frame.args[1] | |||
local item = get_json_item(item_name) | |||
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end | |||
local cost = 0 | |||
local cur_item = item | |||
repeat | |||
cost = cost + cur_item["Cost"] | |||
if(cur_item["Components"] == nil) then | |||
break | |||
end | |||
cur_item = data[cur_item["Components"][1]] | |||
until cur_item == nil | |||
return Format(cost) | |||
end | |||
-- returns the table of a specific item | -- returns the table of a specific item | ||