- Joined
- Nov 17, 2010
- Messages
- 6,832
- Solutions
- 586
- Reaction score
- 5,414
0.3.7
Been wracking my brain for a couple of hours, and still no idea why this is happening.
I can easily get the values if I simply print the exact location, but trying to find the items by going through the loops.. just not working for me.
I've stripped my over-all script down to the bare minimum, so you guys can see what I'm doing..
Generally I'm trying to find the weight of all items , including containers, from inside the table.
I would use this value somewhere else eventually, but that's the jist of it.
For this example it's trying to find the brown backpack, with a green backpack inside, which contains a steel helmet.
Of course, this is useless, but it's just testing the functionality of the script.
Visually, it would look like this.
Been wracking my brain for a couple of hours, and still no idea why this is happening.
I can easily get the values if I simply print the exact location, but trying to find the items by going through the loops.. just not working for me.
I've stripped my over-all script down to the bare minimum, so you guys can see what I'm doing..
Generally I'm trying to find the weight of all items , including containers, from inside the table.
I would use this value somewhere else eventually, but that's the jist of it.
For this example it's trying to find the brown backpack, with a green backpack inside, which contains a steel helmet.
Of course, this is useless, but it's just testing the functionality of the script.
Visually, it would look like this.
Code:
[22:9:51.593] [Error - Action Interface]
[22:9:51.593] data/actions/scripts/aaCarlExampleScripts/easy_chests_test.lua:onUse
[22:9:51.593] Description:
[22:9:51.593] ...ns/scripts/aaCarlExampleScripts/easy_chests_test.lua:29: attempt to get length of field 'inside' (a nil value)
[22:9:51.593] stack traceback:
[22:9:51.593] ...ns/scripts/aaCarlExampleScripts/easy_chests_test.lua:29: in function 'getAllItemWeight'
[22:9:51.593] ...ns/scripts/aaCarlExampleScripts/easy_chests_test.lua:47: in function <...ns/scripts/aaCarlExampleScripts/easy_chests_test.lua:44>
Code:
local t = {
[1] = {aid = 45801, use_container = 1, container = 1988, inside = {
[1] = { use_container = 1, container = 1998, inside = {
[1] = { item_id = 2457, item_count = 1 },
[2] = { item_id = 2457, item_count = 1 }
}
},
[2] = { use_container = 0, item_id = 12649, item_count = 1 }
}
}
}
local n = 0
local m = 0
function getAllItemWeight(weight)
local items = {}
local count = {}
local weight = 0
if t[n].use_container == 1 then
table.insert(items, t[n].container)
table.insert(count, 1)
end
for i = 1, #t[n].inside do
if t[n].use_container == 1 then
table.insert(items, t[n].inside[i].container)
table.insert(count, 1)
m = i
for i = 1, #t[n].inside[m].inside do -- line 29
table.insert(items, t[n].inside[m].inside[i].item_id)
table.insert(count, t[n].inside[m].inside[i].item_count)
end
else
table.insert(items, t[n].inside[i].item_id)
table.insert(count, t[n].inside[i].item_count)
end
end
for i = 1, #items do
weight = (weight + (getItemWeightById(items[i], count[i])))
end
return weight
end
function onUse(cid, item, fromPosition, itemEx, toPosition)
for i = 1, #t do
n = i
print(getAllItemWeight(weight))
end
return true
end
Last edited: