Okay - so line 24 is the following:
local amt = emcValue*v
Do note that 5 lines above it you localized your variable emcValue - means that it's only accessible in your if statement ( from line 18 tp 20 ). As it was never used before in that program, on line 24 it'll be nil of course.
Secondly v is localized to the previous for loop - meaning it's only accessible inbetween lines 5 and 8 or 11 and 13; do note though that these v's are different from each other as they're localized to their matching loop.
Also i think you did not exactly understand my code - it saves a key in the items table that is named after the item display name. As there could be multiple types of items in that chest, for each item it'll create a new key in that table.
For example if we have 32 Cobblestone and 132 Diamonds in that chest, the table would look like this:
{
[ "Diamond" ] = 132,
[ "Cobblestone" ] = 32,
}
That means that the different item amounts are stored in that table and you could, for example, access them with items.Diamond or items.Cobblestone .
I'd recommend you to create a table with all your EMC values stored in it and the matching item names as keys.
The code could then look like this:
local itemValues = {
[ "Diamond" ] = 8192,
[ "Iron Ingot" ] = 32,
[ "Iron Ore" ] = 64,
}
local stacks, valueInChest = peripheral.call( "container_chest_3", "getAllStacks" ), 0
for k, v in pairs( stacks ) do
v = type( v.all ) == "function" and v.all() or v
if itemValues[ v.display_name ] then --# That item is registered in our database
valueInChest = valueInChest + itemValues[ v.display_name ]*v.qty --# Consider the amount, of course
else
print( "Item called '" .. v.display_name .. "' is not yet registered in database." )
end
end
Now you have your total item value stored in valueInChest - it'll not only work with diamonds, but also with all other kinds of items.
You could also set up a table with all the unknown items, so that they won't get pulled from the chestand the user may take them back.
As you're german, too, I could also offer you to send me a PM with your Skype username or a TeamSpeak address so we could meet up and discuss that whole thing in our native language ;)/>