FANDOM


local p = {}
 
function getNumeral( number )
  if number ==  1 then return "I"
  elseif number == 2 then return "II"
  elseif number == 3 then return "III"
  elseif number == 4 then return "IV"
  elseif number == 5 then return "V"
  elseif number == 6 then return "VI"
  elseif number == 7 then return "VII"
  elseif number == 8 then return "VIII"
  elseif number == 9 then return "IX"
  elseif number == 10 then return "X"
  else return "???"
  end
end
 
function p.Challenge( frame )
  local out = ""
  local args = frame:getParent().args
  local name = args[1]
  local format_string = args[2]
  local numArgs = getArgsLength(args)
  if numArgs % 2 == 0 then -- No extra line
    for i = 3, numArgs, 2 do
      if args.bgcolor then
        out = out .. string.format("\n|-\n|bgcolor='%s'|%s %s\n|%s\n|%s", args.bgcolor, name, getNumeral((i - 1) / 2), string.gsub(format_string, '?', args[i]), args[i+1])
      else
        out = out .. string.format("\n|-\n|%s %s\n|%s\n|%s", name, getNumeral((i - 1) / 2), string.gsub(format_string, "?", args[i]), args[i+1])
      end
    end
  else -- Honestly, this could *probably* be done without this second block of code below
    for i = 3, numArgs - 1, 2 do
      if args.bgcolor then
        out = out .. string.format("\n|-\n|bgcolor='%s\'|%s %s\n|%s\n|%s", args.bgcolor, name, getNumeral((i - 1) / 2), string.gsub(format_string, '?', args[i]), args[i+1])
      else
        out = out .. string.format("\n|-\n|%s %s\n|%s\n|%s", name, getNumeral((i - 1) / 2), string.gsub(format_string, "?", args[i]), args[i+1])
      end
    end
    if args.bgcolor then
      out = out .. string.format("\n|-\n|bgcolor='%s'|More %s?\n|%s\n|?", args.bgcolor, name, format_string)
    else
      out = out .. string.format("\n|-\n|More %s?\n|%s\n|?", name, format_string)
    end
  end
  return out
end
 
function getArgsLength( things ) -- Conveinence method to get the number of positional arguments passed via {{#invoke}}, since frame.args is a metatable (table.getn() and #frame.args won't work)
  local max = 0
  for i, v in ipairs(things) do
    max = i
  end
  return max 
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.