the code i have so far is:
--item list + quantity + side bundle is on + colour to pulse
available_items = {
[1] = {item = "gold bar", quantity = 32, side = "left", color = "yellow"},
[2] = {item = "sliver bar", quantity = 32, side = "left", color = "white"},
[3] = {item = "iron bar", quantity = 32, side = "left", color = "gray"},
[4] = {item = "tin bar", quantity = 32, side = "left", color = "lightgray"},
[5] = {item = "copper bar", quantity = 32, side = "left", color = "orange"},
[6] = {item = "uranium bar", quantity = 32, side = "left", color = "green"},
[7] = {item = "uu matter", quantity = 32, side = "left", color = "purple"},
[8] = {item = "diamond", quantity = 32, side = "left", color = "cyan"},
[9] = {item = "ruby", quantity = 32, side = "left", color = "pink"},
[10] = {item = "sapphire", quantity = 32, side = "left", color = "blue"},
[11] = {item = "emerald", quantity = 32, side = "left", color = "lime"},
[12] = {item = "coal", quantity = 32, side = "left", color = "black"},
[13] = {item = "lapis", quantity = 32, side = "left", color = "lightblue"},
[14] = {item = "redstone", quantity = 32, side = "left", color = "red"},
[15] = {item = "nikolite", quantity = 32, side = "left", color = "magenta"},
}
cart = { } --creates the cart table for items to be added to
--clear screen function (lazyness)
function clear()
term.clear()
term.setCursorPos(1,1)
end
--print content of cart
function checkout()
clear()
for i = 1, #cart do
print( cart[i].quantity .. string.rep(" ", 4-(string.len(tostring(cart[i].quantity)))) .. cart[i].item )
sleep(0.5)
end
print("\nEnd of cart")
write("Press enter") read()
end
--main program loop
while true do
clear()
print("choose a number")
print("type 'checkout' to go to checkout")
for i = 1, #available_items do
print( i .. string.rep(" ", 4-(string.len(tostring(i)))) .. available_items[i].item )
end
choice = read()
if choice == "checkout" then
checkout()
else
choice = tonumber(choice)
if available_items[choice] then
table.insert(cart, {item = available_items[choice].item, quantity = available_items[choice].quantity})
print("Added " .. available_items[choice].quantity .. " Of " .. available_items[choice].item .. ".")
sleep (1)
end
end
end
so far, the program prints a list of all available items and their associated number. you can enter a number and 32 of the item associated with that item is added to a cart, typing checkout lists the content of your cart. that's all it does. i need help getting it finished. i have tried myself but have gotten almost nowhere. i know the basics of tables(as you can see from the code) but even that i had a little help with to begin with.
each item has a side and color associated with it to help with scalability (so i can just add or remove stuff from the "available_items" table and those items will be available)
the system works by having 1 bundle on each side connected to a set of 16 retrievers per cable in the basement of the building. when an item is requested, the appropriate color on the appropriate bundle is pulsed a number of times to retrieve the right amount.
e.g. if you requested 64 gold bar, the yellow wire on the left side bundle would be pulsed twice (64/32 = 2) and 64 gold bar would end up in the chest.
this is part i'm having trouble implementing. getting it to work its way through the cart and request each item in sequence.
any help you could give would be extremely appreciated.
ps. i know the current program only adds the items name and quantity to the cart, not its associated side or color.