Codex NG
Recurrent Flamer
- Joined
- Jul 24, 2015
- Messages
- 2,994
- Solutions
- 12
- Reaction score
- 1,657
The goal of this thread is to show you that learning the core language lua is important which allows you to write additional code which can make your life easier as a developer.
Code:
function rangeChance(n, m)
local t = {}
for x = 1, m do
t[x] = {}
if x == 1 then
t[x][1] = x
t[x][2] = n
else
t[x][1] = x * n - n
t[x][2] = (x * n)
end
end
return t
end
It could also be written like this
Code:
function rangeChance(n, m)
local t = {}
for x = 1, m do
t[x] = {}
t[x][1] = x == 1 and x or x * n - n
t[x][2] = x == 1 and n or (x * n)
end
return t
end
So what does this do?
I am glad you asked!
It returns a table of both min and max values
For instances lets say you wanted to generate a series of conditions like if else etc to give someone an item or buff
Code:
local range = 10
local amount = 7
local x = rangeChance(range, amount)
Code:
for k, v in pairs(x) do
print(v[1], v[2])
end
Code:
1 10
10 20
20 30
30 40
40 50
50 60
60 70
Its a simple way to speed up the long drawn out range values.
Last edited: