beenii
Well-Known Member
- Joined
- Jul 26, 2010
- Messages
- 586
- Solutions
- 1
- Reaction score
- 58
hi, i have table for chances, works fine but have error in console
lua:46: attempt to index a nil value
stack traceback:
[C]: in function '__index'
line 46:
local count = math.random(newtable[rand].min, newtable[rand].max)
code complete:
lua:46: attempt to index a nil value
stack traceback:
[C]: in function '__index'
line 46:
local count = math.random(newtable[rand].min, newtable[rand].max)
code complete:
Code:
local config = {
[1] = {chance = 4500, min = 1, max = 3},
[2] = {chance = 1300, min = 4, max = 5},
[3] = {chance = 500, min = 6, max = 8},
[4] = {chance = 300, min = 9, max = 10},
[5] = {chance = 100, min = 11, max = 13}
}
local a = 0
local newtable = {}
for i = 1, #config do
a = a + config[i].chance
for j = i, config[i].chance do
table.insert(newtable, config[i])
end
end
local rand = math.random(1,a)
local count = math.random(newtable[rand].min, newtable[rand].max)