Module:EncounterTable: Difference between revisions

42 bytes removed ,  18:32, 12 November 2019
should probably work now
No edit summary
(should probably work now)
Line 34: Line 34:
end
end
local ret = {}
local ret = {}
for m in gmatch(text, pattern, plain) do
for m in p.gsplit(text, pattern, plain) do
ret[#ret+1] = m
ret[#ret+1] = m
end
end
Line 72: Line 72:
  end
  end
   
   
  --second pass: first row is either an item of a table (where the output is Item from (table)
--format table.
   local finalTable = {}
   local finalTable = {}
   for i, row in ipairs(table) do
  local str = ''
    if row['table'] == 'none' then
   for i, row in ipairs(result) do
      if row['item'] == 'none' then
    finalTable[i]={}
        error('A table or item must be specified!')
    if row["table"] == 'none' then
      else
      if row["item"] == 'none' then
        finalTable['item'] = '[[' .. row['item'] .. ']]'
        error('A table or item must be specified!')
      end
      else
    elseif row['item'] ~= 'none' then
        finalTable[i]['item'] = '[[' .. row['item'] .. ']]'
      error('A table and item cannot be specified at the same time. Choose one ya silly')
      end
    else
    elseif row["item"] == 'none' then  
      finalTable['item'] = 'Item from [[EncounterTable:' .. row['table'] .. '|' .. row['table'] .. ']]'
      finalTable[i]['item'] = 'Item from [[EncounterTable:' .. row['table'] .. '|' .. row['table'] .. ']]'
    end
    else
  -- dice tooltip quantity
      error('What')
     finalTable['quantity'] = frame:expandTemplate{title='Dice tooltip', args={row['quantity']}}
    end
     finalTable['weight'] = row['weight']
    -- dice tooltip quantity
     finalTable[i]['quantity'] = frame:expandTemplate{title='Dice tooltip', args={row['quantity']}}
     --finalTable[i]['quantity'] = row['quantity']
    finalTable[i]['weight'] = row['weight']
   -- calculate final chance
   -- calculate final chance
     finalTable['chance'] = row['weight']/totalWeight
     finalTable[i]['chance'] = row['weight']/totalWeight
   end
   end
--format table.
  return (p.formatTable(finalTable))
  return p.formatTable(finalTable)
end
end