This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
JamiePhonic's profile picture

computer controlled item request system

Started by JamiePhonic, 19 January 2013 - 05:52 AM
JamiePhonic #1
Posted 19 January 2013 - 06:52 AM
in my Tekkit world, i have a huge factory, that huge factory is connected to a huge quarry that mines stuff and sends it to the factory to be processed (gold ore into gold bar and so on)
just now, players need to go to a huge wall of buttons and press the button with item and amount they want, either 32 or 64. there are 32 possible items you can request. that's a wall with 64 buttons on it, plus signs to label it all = 1 huge wall taking up allot of unnecessary space. i want to compress this into a computer with 1 chest and move all the machinery under ground (keeping the same 2 quantities).
thing is, i have no idea where to start. i have a basic knowledge of tables and such which i know i'm going to have to use to make this work.
here's what i'm trying to do.

computer starts up, shows a list of items you can retrieve. use up and down arrows to change screens, enter a number to add it to your "cart"
if user types checkout, order is displayed, user enters yes, items are retrieved and put in chest, enters no to go back and make changes. it also needs to be CTRL+T proof if possible, i think you use pcall for that, but i cant work it out (yes, i did check the wikis for answers first)

i know it should be something like

cart = { }

if option == 1 then
cart.insert(cart, item = "stone", quty = "64")
but its how to perform the request when the user confirms after "checkout"

the computer has 2 bundled cables coming out of each side (left and right) and i have a list of what each color will retrieve. what i don't know is how to get it to run through the cart table and pulse the correct color on the bundle either once or twice to retrieve the correct amount (32 or 64)

any help would be greatly appreciated :-D
remiX #2
Posted 19 January 2013 - 07:13 AM
What do you use to let the computer know what blocks the quarry has brought in? Interactive sorter with all the id's of blocks and the name or something? O.o

And to insert into a table:

table.insert(cart, {name = "stone", quantity = 64})
It would be something like that, hm?

Also, when using code, please place it into [code]code here…[/code] tags :)/>
JamiePhonic #3
Posted 19 January 2013 - 08:21 AM
What do you use to let the computer know what blocks the quarry has brought in? Interactive sorter with all the id's of blocks and the name or something? O.o

And to insert into a table:

table.insert(cart, {name = "stone", quantity = 64})
It would be something like that, hm?

Also, when using code, please place it into [code]code here…[/code] tags :)/>
fixed the code tag problem, please read the part after it.
The Lone Wolfling #4
Posted 19 January 2013 - 09:40 AM
My suggestion:

Have the items be in a table, with the item name as the index, and a subtable of the side and color as the value.

For example:
items.stone = {side="left", color=colors.white}

This allows you to later on expand the facility easily. It also allows you to use the same table for printing the cart as getting the items, which means that the code is less brittle. It may be overkill, though.

Then, as for getting the items, there are two methods. The first is simpler, but slower, whereas the second is more complex but faster.
(Consider the case where you want to get two different items - the first would get the first item then the second, the second would get both at the same time)

First method:
for reqItem, amount in pairs(cart) do
	for i=32,amount,32 do
		redstone.setBundledOutput(reqItem[side], reqItem[color]) -- pulse wire
		sleep(0.05) -- sleep a tick
		redstone.setBundledOutput(reqItem[side], 0)
		sleep(0.2) -- wait for filter to finish
	end
end

Second method:

pulseTime = {}
for reqItem, amount in pairs(cart) do
	for i=32,amount,32 do
		pulseTime[i][reqItem[side]] = pulseTime[i][reqItem[side]] + reqItem[color]
	end
end
for _,pulse in ipairs(pulseTime) do
	for side, data in pairs(pulse) do
		redstone.setBundledOutput(side, data) -- pulse wires
	end
	sleep(0.05) -- sleep a tick
	for side, data in pairs(pulse) do
		redstone.setBundledOutput(side, 0)
	end
	sleep(0.2) -- wait for filter to finish
end

Note that this code is completely untested, and is probably at least slightly wrong.
JamiePhonic #5
Posted 20 January 2013 - 12:07 AM
My suggestion:

Have the items be in a table, with the item name as the index, and a subtable of the side and color as the value.

For example:
items.stone = {side="left", color=colors.white}

This allows you to later on expand the facility easily. It also allows you to use the same table for printing the cart as getting the items, which means that the code is less brittle. It may be overkill, though.

Then, as for getting the items, there are two methods. The first is simpler, but slower, whereas the second is more complex but faster.
(Consider the case where you want to get two different items - the first would get the first item then the second, the second would get both at the same time)

First method:
for reqItem, amount in pairs(cart) do
	for i=32,amount,32 do
		redstone.setBundledOutput(reqItem[side], reqItem[color]) -- pulse wire
		sleep(0.05) -- sleep a tick
		redstone.setBundledOutput(reqItem[side], 0)
		sleep(0.2) -- wait for filter to finish
	end
end

Second method:

pulseTime = {}
for reqItem, amount in pairs(cart) do
	for i=32,amount,32 do
		pulseTime[i][reqItem[side]] = pulseTime[i][reqItem[side]] + reqItem[color]
	end
end
for _,pulse in ipairs(pulseTime) do
	for side, data in pairs(pulse) do
		redstone.setBundledOutput(side, data) -- pulse wires
	end
	sleep(0.05) -- sleep a tick
	for side, data in pairs(pulse) do
		redstone.setBundledOutput(side, 0)
	end
	sleep(0.2) -- wait for filter to finish
end

Note that this code is completely untested, and is probably at least slightly wrong.

so something like:

items = {
[1] = {item = "stone", side = "left", value = "64"},
[2] = {item = "coal", side = "left", value = "64"},
}
for the item list then? how would i take a selected item (say number 2) and copy it into the cart table?
or would i just use 32 if statements with an "items.insert" for each?
The Lone Wolfling #6
Posted 20 January 2013 - 07:01 AM
so something like:

items = {
[1] = {item = "stone", side = "left", value = "64"},
[2] = {item = "coal", side = "left", value = "64"},
}
for the item list then? how would i take a selected item (say number 2) and copy it into the cart table?
or would i just use 32 if statements with an "items.insert" for each?
You're indexing by item number - I was indexing by item name. They are pretty much equivalent, but indexing by item number will requires some minor changes to the code I've given - I'll update it and repost it below.

What is "value"? Do you mean the integer representation of the color? If so then you don't want to store it as a string, and colors.x would be more readable. Other than that you've pretty much got it, though. One hint - you can drop the keys entirely, as lua will automatically assign numbers starting at one if you omit the key.

items = {
{item = "stone", side = "left", color = colors.black},
{item = "coal", side = "left", color = colors.white}
}
print(items[1]['item']) -- prints stone


You can just do the following to add a selected item by number and amount into the cart table:

cart[itemNumber] = (cart[itemNumber] or 0) + amount

EDIT: Here is the updated code:

SpoilerFirst method:
for reqItemNum, amount in pairs(cart) do
    reqItem = items[reqItemNum]
	for i=32,amount,32 do
		redstone.setBundledOutput(reqItem[side], reqItem[color]) -- pulse wire
		sleep(0.05) -- sleep a tick
		redstone.setBundledOutput(reqItem[side], 0)
		sleep(0.2) -- wait for filter to finish
	end
end

Second method:

pulseTime = {}
for reqItemNum, amount in pairs(cart) do
    reqItem = items[reqItemNum]
	for i=32,amount,32 do
		pulseTime[i][reqItem[side]] = pulseTime[i][reqItem[side]] + reqItem[color]
	end
end
for _,pulse in ipairs(pulseTime) do
	for side, data in pairs(pulse) do
	    redstone.setBundledOutput(side, data) -- pulse wires
	end
	sleep(0.05) -- sleep a tick
	for side, data in pairs(pulse) do
		redstone.setBundledOutput(side, 0)
	end
	sleep(0.2) -- wait for filter to finish
end
JamiePhonic #7
Posted 20 January 2013 - 08:16 AM
so something like:

items = {
[1] = {item = "stone", side = "left", value = "64"},
[2] = {item = "coal", side = "left", value = "64"},
}
for the item list then? how would i take a selected item (say number 2) and copy it into the cart table?
or would i just use 32 if statements with an "items.insert" for each?
You're indexing by item number - I was indexing by item name. They are pretty much equivalent, but indexing by item number will requires some minor changes to the code I've given - I'll update it and repost it below.

What is "value"? Do you mean the integer representation of the color? If so then you don't want to store it as a string, and colors.x would be more readable. Other than that you've pretty much got it, though. One hint - you can drop the keys entirely, as lua will automatically assign numbers starting at one if you omit the key.

items = {
{item = "stone", side = "left", color = colors.black},
{item = "coal", side = "left", color = colors.white}
}
print(items[1]['item']) -- prints stone


You can just do the following to add a selected item by number and amount into the cart table:

cart[itemNumber] = (cart[itemNumber] or 0) + amount

EDIT: Here is the updated code:

SpoilerFirst method:
for reqItemNum, amount in pairs(cart) do
	reqItem = items[reqItemNum]
	for i=32,amount,32 do
		redstone.setBundledOutput(reqItem[side], reqItem[color]) -- pulse wire
		sleep(0.05) -- sleep a tick
		redstone.setBundledOutput(reqItem[side], 0)
		sleep(0.2) -- wait for filter to finish
	end
end

Second method:

pulseTime = {}
for reqItemNum, amount in pairs(cart) do
	reqItem = items[reqItemNum]
	for i=32,amount,32 do
		pulseTime[i][reqItem[side]] = pulseTime[i][reqItem[side]] + reqItem[color]
	end
end
for _,pulse in ipairs(pulseTime) do
	for side, data in pairs(pulse) do
		redstone.setBundledOutput(side, data) -- pulse wires
	end
	sleep(0.05) -- sleep a tick
	for side, data in pairs(pulse) do
		redstone.setBundledOutput(side, 0)
	end
	sleep(0.2) -- wait for filter to finish
end
sorry, value is meant to be quantity, the retrievers are set to retrieve 32 of something each time they are pulsed, so requesting 64 needs 2 pulses, 96 = 3 pulses and so on.

the code for adding to cart would be along the lines of:

choice =read()
if choice = 1 then
cart.insert(item = stone, quantity = 32, color = red, side = left)
end
this is meant to read as:
if choice is "1", add 32 of stone to the cart, pulse the red cable on the left side bundle to request.
i would like it so that if a user requests 2 lots of 32 stone, it shows up as just 1 of 64 in the checkout screen.

if a better way of doing the requesting part is to use a for loop to run through the table and use the color and side to populate an "rs.setbundledoutput("side", "color")" command then that's fine.
ChunLing #8
Posted 20 January 2013 - 09:38 AM
You can just index a table rather than using a loop to traverse it. So the table is a lot better.
JamiePhonic #9
Posted 20 January 2013 - 10:15 AM
You can just index a table rather than using a loop to traverse it. So the table is a lot better.
not a clue what that means, sorry
remiX #10
Posted 20 January 2013 - 11:14 AM
And to insert into a table:
table.insert(cart, {name = "stone", quantity = 64})

Not
cart.insert(..)

And to change values:


choice = read()
if choice = "1" then
  for i = 1, #cart do
    if cart[i].item == "stone" then
      cart[i].quantity = cart[i].quantity + 32 -- adds 32 to the current quantity
    end
  end
end

That's how you iterate through a table
ChunLing #11
Posted 20 January 2013 - 05:10 PM
Yes, but we don't have to iterate through the table if we just index the table by the available options. When an option is input, you just look for a table entry indexed by that option, and if there is one, use that entry.
remiX #12
Posted 20 January 2013 - 08:18 PM
Yes, but we don't have to iterate through the table if we just index the table by the available options. When an option is input, you just look for a table entry indexed by that option, and if there is one, use that entry.

You mean like this?

t_items = {
["stone"] = 32,
["grass"] = 64
}

if choice == "1" then
	t_items["stone"] = t_items["stone"] + 32
end
ChunLing #13
Posted 20 January 2013 - 10:10 PM
Possibly. I haven't really been able to make out what all the options would be as envisioned by the OP.
remiX #14
Posted 20 January 2013 - 10:20 PM
Yeah, I just like keeping it neat within tables like {item = "stone", quantity = 32}. But I guess for tables that are quite big, your suggestion would probably fit better.
JamiePhonic #15
Posted 21 January 2013 - 03:12 AM
ok, so far i have:
Spoiler

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 = { }
choice = read()
if choice = "1" then
table.insert(cart, {name = "stone", quantity = 32})
elseif
choice = "2" then
table.insert(cart, {name = "stone", quantity = 32})
elseif
choice = "3" then
table.insert(cart, {name = "stone", quantity = 32})
elseif
choice = "4" then
table.insert(cart, {name = "stone", quantity = 32})
elseif
choice = "5" then
table.insert(cart, {name = "stone", quantity = 32})
elseif
choice = "6" then
table.insert(cart, {name = "stone", quantity = 32})
elseif
choice = "7" then
table.insert(cart, {name = "stone", quantity = 32})
elseif
choice = "8" then
table.insert(cart, {name = "stone", quantity = 32})
elseif
choice = "9" then
table.insert(cart, {name = "stone", quantity = 32})
elseif
choice = "10" then
table.insert(cart, {name = "stone", quantity = 32})
end
i know they all say stone, its only example…

what im trying to do is:
Spoiler


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 = { }

choice = read()
if choice = "1" then
--item 1 from available_items into cart, if already there, just update quantity in cart
elseif
choice = "2" then
--item 2 from available_items into cart, if already there, just update quantity in cart
elseif
choice = "3" then
--item 3 from available_items into cart, if already there, just update quantity in cart
elseif
choice = "4" then
--item 4 from available_items into cart, if already there, just update quantity in cart
elseif
choice = "5" then
--item 5 from available_items into cart, if already there, just update quantity in cart
elseif
choice = "6" then
--item 6 from available_items into cart, if already there, just update quantity in cart
elseif
choice = "7" then
--item 7 from available_items into cart, if already there, just update quantity in cart
elseif
choice = "8" then
--item 8 from available_items into cart, if already there, just update quantity in cart
elseif
choice = "9" then
--item 9 from available_items into cart, if already there, just update quantity in cart
elseif
choice = "10" then
--item 10 from available_items into cart, if already there, just update quantity in cart
elseif choice = "checkout" then
checkout()
end
the checkout function will clear the screen and display what is the the "cart" (including quantities) and give the user a choice to either request it, or go back to make changes. this is the hardest part because it will need to go through the table and (for example) know that, in order to get 64 of gold bar, it needs to pulse the yellow cable on the left side of the computer twice. it also needs to be scalable. only 10 options are shown here. i have 32 to request
remiX #16
Posted 21 January 2013 - 03:20 AM
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
JamiePhonic #17
Posted 21 January 2013 - 09:14 AM
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.
remiX #18
Posted 21 January 2013 - 09:18 AM
that didn't work. it gave an error about atempting to compare string to number expected, got string.

That's because within your available_items table, you have the quantity of each block as a string instead of a number.
Remove the " " and it should work.

EDIT:

Also, it will here on this line:
print( cart[i] )

Because cart is a table.

Do this:
print( cart[i].quantity .. "  " .. cart[i].item )

Or try this.

Spoiler

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()
	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("Click enter") read()
end

while true do
	clear()
	choice = read()

	if choice == "checkout" then
		checkout()
	else
		choice = tonumber(choice)
		if available_items[choice] then
			if available_items[choice].quantity >= 32 then
				table.insert(cart, {item = available_items[choice].item, quantity = available_items[choice].quantity})
				print("Added " .. available_items[choice].item .. " with quantity of " .. available_items[choice].quantity .. ".")
				available_items[choice].quantity = 0
			else
				print("Item " .. available_items[choice].item .. " has no more quantity left.")
			end
			sleep (1)
		end
	end
end
JamiePhonic #19
Posted 21 January 2013 - 09:35 AM
that didn't work. it gave an error about atempting to compare string to number expected, got string.

That's because within your available_items table, you have the quantity of each block as a string instead of a number.
Remove the " " and it should work.

EDIT:

Also, it will here on this line:
print( cart[i] )

Because cart is a table.

Do this:
print( cart[i].quantity .. "  " .. cart[i].item )

Or try this.

Spoiler

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()
	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("Click enter") read()
end

while true do
	clear()
	choice = read()

	if choice == "checkout" then
		checkout()
	else
		choice = tonumber(choice)
		if available_items[choice] then
			if available_items[choice].quantity >= 32 then
				table.insert(cart, {item = available_items[choice].item, quantity = available_items[choice].quantity})
				print("Added " .. available_items[choice].item .. " with quantity of " .. available_items[choice].quantity .. ".")
				available_items[choice].quantity = 0
			else
				print("Item " .. available_items[choice].item .. " has no more quantity left.")
			end
			sleep (1)
		end
	end
end
here is the result using my code
Spoiler
and yours
Spoiler

it gives an error when i try to add another 32 of an item (X has no more quantity left)
the quantity in the available_items table is meant to be the quantity to add to the cart, not the quantity available, however i may add the function later
remiX #20
Posted 21 January 2013 - 09:40 AM
Yeah, check my edit.
When I said "Also, it will here on this line" I mean: also, it will error on this line because you're trying to print a table which is why you're getting table: adfwdcvre.

Check the code in the spoiler of my edit
JamiePhonic #21
Posted 21 January 2013 - 09:44 AM
Yeah, check my edit.
When I said "Also, it will here on this line" I mean: also, it will error on this line because you're trying to print a table which is why you're getting table: adfwdcvre.

Check the code in the spoiler of my edit
ok, check my edits.
remiX #22
Posted 21 January 2013 - 09:50 AM
Oh, I thought you wanted it to remove the quantity of the item when you add it to the list :P/>

Remove these three lines within my code:


available_items[choice].quantity = 0
else
print("Item " .. available_items[choice].item .. " has no more quantity left.")
JamiePhonic #23
Posted 21 January 2013 - 10:06 AM
Oh, I thought you wanted it to remove the quantity of the item when you add it to the list :P/>

Remove these three lines within my code:


available_items[choice].quantity = 0
else
print("Item " .. available_items[choice].item .. " has no more quantity left.")
yea, getting the computer to keep track of whats in the chest would just be too complicated. (may be CC Sensors?)

also, when i go to checkout, it shows 2 entries of an item as separate items, how do you get it to just update the quantity if its already in the cart? (not a must have) i gave it a go but didn't get very far
following that, is your code for pulsing the cables based on the content of the cart still valid?
SpoilerFirst method:

for reqItemNum, amount in pairs(cart) do
		reqItem = items[reqItemNum]
		for i=32,amount,32 do
				redstone.setBundledOutput(reqItem[side], reqItem[color]) -- pulse wire
				sleep(0.05) -- sleep a tick
				redstone.setBundledOutput(reqItem[side], 0)
				sleep(0.2) -- wait for filter to finish
		end
end
Second method:

pulseTime = {}
for reqItemNum, amount in pairs(cart) do
		reqItem = items[reqItemNum]
		for i=32,amount,32 do
				pulseTime[i][reqItem[side]] = pulseTime[i][reqItem[side]] + reqItem[color]
		end
end
for _,pulse in ipairs(pulseTime) do
		for side, data in pairs(pulse) do
				redstone.setBundledOutput(side, data) -- pulse wires
		end
		sleep(0.05) -- sleep a tick
		for side, data in pairs(pulse) do
				redstone.setBundledOutput(side, 0)
		end
		sleep(0.2) -- wait for filter to finish
end
JamiePhonic #24
Posted 24 January 2013 - 06:39 AM
bump :blink:/>
ChunLing #25
Posted 24 January 2013 - 08:54 AM
Sorry, but you can just PM a particular member if you need a response. Generally, bumping a thread without providing new information (such as, "I attempted to run the code with the suggested modifications and here is what happened") is not as productive as testing the code to see if it works with the suggested modifications.