Module:RPG: Difference between revisions
Jump to navigation
Jump to search
(Created page with "-- Module for rolling RPG dice local p = {} -- Function to roll dice function p.rollDice(diceString) local num, sides, modifier = string.match(diceString, "(%d+)d(%d+)([%+%-]?%d*)") num = tonumber(num) or 1 sides = tonumber(sides) or 6 modifier = tonumber(modifier) or 0 local total = modifier for _ = 1, num do total = total + math.random(sides) end return total end return p") |
No edit summary |
||
Line 12: | Line 12: | ||
for _ = 1, num do | for _ = 1, num do | ||
total = total + math.random(sides) | total = total + math.random(1, sides) | ||
end | end | ||
Revision as of 15:40, 27 January 2024
Lua error at line 6: bad argument #1 to 'match' (string expected, got table).
- Lua error at line 6: bad argument #1 to 'match' (string expected, got table).
- Lua error at line 6: bad argument #1 to 'match' (string expected, got table).
- Lua error at line 6: bad argument #1 to 'match' (string expected, got table).
- Lua error at line 6: bad argument #1 to 'match' (string expected, got table).
- Script error: The function "rollStats" does not exist.
- Script error: The function "rollStats" does not exist.
- Script error: The function "rollStats" does not exist.
- Script error: The function "rollStats" does not exist.
-- Module for rolling RPG dice local p = {} -- Function to roll dice function p.rollDice(diceString) local num, sides, modifier = string.match(diceString, "(%d+)d(%d+)([%+%-]?%d*)") num = tonumber(num) or 1 sides = tonumber(sides) or 6 modifier = tonumber(modifier) or 0 local total = modifier for _ = 1, num do total = total + math.random(1, sides) end return total end return p