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

Check for changes in bundledcables

Started by XSturb, 10 June 2013 - 05:59 PM
XSturb #1
Posted 10 June 2013 - 07:59 PM
Hi.
I'm trying to make a program that checks for certain inputs goes false or true and then perform some code to my monitor.
The problem I'm having is that i don't know how to check if an input just got true or false or if it was true or false before it's getting checked.
If you see my code below the white cable will be the only one performing its code because I use an if/elsif statments. How can I change my code so that it checks if an input went true or false instead of checking if they are.



if event == "redstone" and rs.testBundledInput("back",colors.white) == true then
mon.setCursorPos(1,3)
mon.setBackgroundColor(8192)
mon.setTextColor(1)
mon.write("Stop   ")
mon.setCursorPos(1,4)
mon.write("Engines")
elseif event == "redstone" and rs.testBundledInput("back",colors.white) == false then
mon.setCursorPos(1,3)
mon.setBackgroundColor(16384)
mon.setTextColor(1)
mon.write("Start  ")
mon.setCursorPos(1,4)
mon.write("Engines")
elseif event == "redstone" and rs.testBundledInput("back",colors.lightBlue) == true then
mon.setTextScale(2)
mon.setCursorPos(1,6)
mon.setBackgroundColor(8192)
mon.setTextColor(1)
mon.write("LavaShip")
mon.setCursorPos(1,7)
mon.write(" Moving ")
elseif event == "redstone" and rs.testBundledInput("back",colors.lightBlue) == false then
mon.setTextScale(2)
mon.setCursorPos(1,6)
mon.setBackgroundColor(16384)
mon.setTextColor(1)
mon.write("  Move  ")
mon.setCursorPos(1,7)
mon.write("LavaShip")
end

Thanks :)/>
Lyqyd #2
Posted 10 June 2013 - 08:05 PM
Split into new topic.

You could try keeping track of the old state and comparing it to the new state:


local oldState = rs.getBundledInput("back")
while true do
  os.pullEvent("redstone")
  local newState = rs.getBundledInput("back")
  if newState ~= oldState then
    local changedWire = bit.bxor(oldState, newState)
    --use changedWire to perform appropriate actions based on which one changed.
    oldState = newState
  end
end
XSturb #3
Posted 10 June 2013 - 08:24 PM
Thanks this works perfectly. Thank you very much :D/>