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

[Lua][Question] Help with testBundledInput

Started by mzx987, 04 April 2013 - 08:36 AM
mzx987 #1
Posted 04 April 2013 - 10:36 AM
Alright, Ill try to make this short and simple to explain.

I have made a banking system using Redpower2 cables (and LAN cables from Immibis Peripherals).
This currency gets put through a transposer, which goes through a sorting machine, and the currency gets sorted through their respective colored pipes. Once they are through the correct pipe, they get counted through an item detector, which emits a pulse through a specific colored wire that is connected to bundled cables.

Problem: When I insert 2 stacks (e.g. stack of gold bars, and stack of copper bars) of items, they get sorted, but with these multiple redstone pulses going through, the computer mistakens the count more than once. So instead of a total count of 128, I get a number bigger than that.

Im just wondering if there is a way around this, or if my code is even correct:

if event == "redstone" then
if redstone.testBundledInput(side, colors.white) == true then
  count1 = count1 + 1
elseif redstone.testBundledInput(side, colors.orange) == true then
  count2 = count2 + 1
elseif redstone.testBundledInput(side, colors.magenta) == true then
  count3 = count3 + 1
elseif redstone.testBundledInput(side, colors.lightBlue) == true then
  count4 = count4 + 1
elseif redstone.testBundledInput(side, colors.yellow) == true then
  count5 = count5 + 1
elseif redstone.testBundledInput(side, colors.lime) == true then
  count6 = count6 + 1
end
end
(This is just a part of the code.)

EDIT: Not sure if this matters, but I am currently using ComputerCraft 1.5
LBPHacker #2
Posted 04 April 2013 - 10:52 AM
If you have "side" already set, then it's correct.

BTW, you can leave out the " == true" part of the expressions.
mzx987 #3
Posted 04 April 2013 - 11:03 AM
If you have "side" already set, then it's correct.

BTW, you can leave out the " == true" part of the expressions.
Thanks for the tip. :)/>

But now it seems to go below 128 instead of above.

EDIT: Nvm, it goes either way :/
mzx987 #4
Posted 05 April 2013 - 12:32 PM
Is there anyone out there that can help? Or at least tell me if there is a way around this? :/
PixelToast #5
Posted 05 April 2013 - 04:05 PM
its probably because redstone events also trigger when redstone goes off, meaning if one wire goes off while another is on, it will count extra, let me code a fix for you
Symmetryc #6
Posted 05 April 2013 - 04:11 PM
Try this:

if event == "redstone" then
if on then
on = false
if redstone.testBundledInput(side, colors.white) then
  count1 = count1 + 1
elseif redstone.testBundledInput(side, colors.orange) then
  count2 = count2 + 1
elseif redstone.testBundledInput(side, colors.magenta) then
  count3 = count3 + 1
elseif redstone.testBundledInput(side, colors.lightBlue) then
  count4 = count4 + 1
elseif redstone.testBundledInput(side, colors.yellow) then
  count5 = count5 + 1
elseif redstone.testBundledInput(side, colors.lime) then
  count6 = count6 + 1
end
else
on = true
end
PixelToast #7
Posted 05 April 2013 - 04:35 PM
Symmetric: that will only allow counting every other event, wich dosent work verry well with bundled cables
anyway heres my version:
http://ptoast.tk/sl/mzx987
http://pastebin.com/vEruTCyG
mzx987 #8
Posted 07 April 2013 - 04:21 PM
Symmetric: that will only allow counting every other event, wich dosent work verry well with bundled cables
anyway heres my version:
http://ptoast.tk/sl/mzx987
http://pastebin.com/vEruTCyG
Thanks for your help, but Im getting an error with this code.

counter:36: attempt to perform arithmetic __add on nil and number


Did I insert the code right?

local last={false,false,false,false,false,false}
local side = "back"
local count1 = 0
local count2 = 0
local count3 = 0
local count4 = 0
local count5 = 0
local count6 = 0
local lastTimer = nil
while true do
term.clear()
term.setCursorPos(1,1)
print(count1)
print(count2)
print(count3)
print(count4)
print(count5)
print(count6)
print("Total: ".. count1+count2+count3+count4+count5+count6)
local event,arg1,arg2,arg3 = os.pullEvent()
if event == "redstone" then
for l1=1,6 do
if redstone.testBundledInput(side,2^(l1-1)) then
  if not last[l1] then
   _G["count"..l1]=_G["count"..l1]+1 --Line 36
   last[l1]=true
  end
else
  last[l1]=false
end
end
end
mzx987 #9
Posted 14 April 2013 - 05:04 PM
Not sure if its too late but…

Bump.
PixelToast #10
Posted 14 April 2013 - 06:35 PM
derpy me, local files arent stored in _G
try this:

local last={false,false,false,false,false,false}
local count={0,0,0,0,0,0}
local side = "back"
local lastTimer = nil
while true do
term.clear()
term.setCursorPos(1,1)
print(count[1])
print(count[2])
print(count[3])
print(count[4])
print(count[5])
print(count[6])
print("Total: ".. count[1]+count[2]+count[3]+count[4]+count[5]+count[6])
local event,arg1,arg2,arg3 = os.pullEvent()
if event == "redstone" then
for l1=1,6 do
if redstone.testBundledInput(side,2^(l1-1)) then
  if not last[l1] then
   count[l1]=count[l1]+1 --Line 36
   last[l1]=true
  end
else
  last[l1]=false
end
end
end