Jump to content




Check for changes in bundledcables


  • You cannot reply to this topic
2 replies to this topic

#1 XSturb

  • Members
  • 6 posts

Posted 10 June 2013 - 06: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 :)

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 10 June 2013 - 07: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


#3 XSturb

  • Members
  • 6 posts

Posted 10 June 2013 - 07:24 PM

Thanks this works perfectly. Thank you very much :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users