Hm… Try this?
choice = tonumber(read())
if available_items[choice] and available_items[choice].quantity >= 32 then
table.insert(cart, {item = available_items[choice].item, quantity = available_items[choice].quantity})
available_items[choice].qauntity = 0
end
that didn't work. it gave an error about "attempted to compare string to number expected, got string".
using:
available_items = {
[1] = {item = "bold bar", quantity = "32"},
[2] = {item = "sliver bar", quantity = "32"},
[3] = {item = "iron bar", quantity = "32"},
[4] = {item = "tin bar", quantity = "32"},
[5] = {item = "copper bar", quantity = "32"},
[6] = {item = "uranium bar", quantity = "32"},
[7] = {item = "uu matter", quantity = "32"},
[8] = {item = "diamond", quantity = "32"},
[9] = {item = "ruby", quantity = "32"},
[10] = {item = "sapphire", quantity = "32"},
[11] = {item = "emerald", quantity = "32"},
[12] = {item = "coal", quantity = "32"},
[13] = {item = "lapis", quantity = "32"},
[14] = {item = "redstone", quantity = "32"},
[15] = {item = "nikolite", quantity = "32"},
}
cart = { }
--clear screen function (lazyness)
function clear()
term.clear()
term.setCursorPos(1,1)
end
function checkout()
for i=1,#cart do
print( cart[i] )
print ("end of cart")
sleep(2)
end
end
while true do
clear()
choice = read()
if choice == "checkout" then
checkout()
--else choice = tonumber(choice)
else
if available_items[choice] and available_items[choice].quantity >= 32 then
table.insert(cart, {item = available_items[choice].item, quantity = available_items[choice].quantity})
available_items[choice].qauntity = 0
print("added")
sleep (1)
end
end
end
doesnt error, but nothing happens
this copy of the code with print("something") in after each step shows it does run through the code, but doesn't add anything
available_items = {
[1] = {item = "bold bar", quantity = "32"},
[2] = {item = "sliver bar", quantity = "32"},
[3] = {item = "iron bar", quantity = "32"},
[4] = {item = "tin bar", quantity = "32"},
[5] = {item = "copper bar", quantity = "32"},
[6] = {item = "uranium bar", quantity = "32"},
[7] = {item = "uu matter", quantity = "32"},
[8] = {item = "diamond", quantity = "32"},
[9] = {item = "ruby", quantity = "32"},
[10] = {item = "sapphire", quantity = "32"},
[11] = {item = "emerald", quantity = "32"},
[12] = {item = "coal", quantity = "32"},
[13] = {item = "lapis", quantity = "32"},
[14] = {item = "redstone", quantity = "32"},
[15] = {item = "nikolite", quantity = "32"},
}
cart = { }
--clear screen function (lazyness)
function clear()
term.clear()
term.setCursorPos(1,1)
end
function checkout()
print("cart start")
sleep(1)
for i=1,#cart do
print( cart[i] )
end
print ("end of cart")
sleep(1)
end
while true do
clear()
choice = read()
print("input")
sleep(1)
if choice == "checkout" then
print("checkout")
sleep(1)
checkout()
--else choice = tonumber(choice)
else
print("adding")
sleep(1)
if available_items[choice] and available_items[choice].quantity >= 32 then
table.insert(cart, {item = available_items[choice].item, quantity = available_items[choice].quantity})
available_items[choice].qauntity = 0
end
print("added")
sleep(1)
end
end
also, the quantity in the available_items table is the quantity to add to the cart encase you were wondering.