Jump to content




Redstone Detect and Situational toggle


12 replies to this topic

#1 TheWoWClown

  • New Members
  • 10 posts

Posted 27 June 2012 - 05:42 PM

So I was working on this all day today, and could only get the status display to work. What this does is detects all outputs and then charts which ones are on and working. What I want to also happen is, if power is off, I want it to turn on, if the power is on I want it to turn off. I am new to this and just need some help accomplishing it.
print ("Redstone output status list.")
print("Left=", rs.getOutput("left"))
rs.getOutput("left")
if false then
rs.setOutput("left", true)
else
rs.setOutput("left", false)
end
print ("Right=", rs.getOutput("right"))
rs.getOutput("right")
if false then
rs.setOutput("right", true)
else
rs.setOutput("right", false)
end
print ("Bottom=", rs.getOutput("bottom"))
rs.getOutput("bottom")
if false then
rs.setOutput("bottom", true)
else
rs.setOutput("bottom", false)
end
print ("Top=", rs.getOutput("top"))
rs.getOutput("top")
if false then
rs.setOutput("top", true)
else
rs.setOutput("top", false)
end
print ("Back=", rs.getOutput("back"))
rs.getOutput("back")
if false then
rs.setOutput("back", true)
else
rs.setOutput("back", false)
end

Thanks!

#2 Dirkus7

  • Members
  • 148 posts
  • Locationthe Netherlands

Posted 27 June 2012 - 06:14 PM

You are comparing 'false' with 'true', so it will never work. I changed the code and clarified what i did:
Spoiler


#3 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 27 June 2012 - 06:29 PM

A shorter version:
print("Redstone output status list.")
for _,side in ipairs(rs.getSides()) do -- loop through all sides
  print(side, " = ", rs.getOutput(side)) -- print the side and it's state
  rs.setOutput(side, not rs.getOutput(side)) -- switch the output
end


#4 TheWoWClown

  • New Members
  • 10 posts

Posted 27 June 2012 - 06:31 PM

Thank you for the help. This will really help in the build I am planning.

#5 TheWoWClown

  • New Members
  • 10 posts

Posted 27 June 2012 - 07:14 PM

Okay I am sorry to waste your time again, but I split it into two programs so that the status check would actually be useful. Now, I have s monitor above my computer, and was wondering how I would be able to make the status updates project right onto the monitor so that I can see it without going into the console. The new code for the status update is
print("Redstone output status list.")
for _,side in ipairs(rs.getSides()) do
  print(side, " = ", rs.getOutput(side))
end
I want it to project onto a screen, and will probably install it on it's own computer so that I can use my main computer for other things. If you could please help me again it would be amazing. And I am sorry for wasting your time at first Dirkus.

#6 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 27 June 2012 - 07:30 PM

Here you go:
local side = "top" -- the side the monitor is on

if peripheral.isPresent(side) and peripheral.getType(side) == "monitor" then
  term.redirect(peripheral.wrap(side))
else
  print("Monitor not found")
  return
end

print("Redstone output status list.")
for _,side in ipairs(rs.getSides()) do
  print(side, " = ", (rs.getOutput(side) and "On") or "Off") -- print "On" and "Off" instead of true/false
end

term.restore()
Not tested, but it should work.

#7 TheWoWClown

  • New Members
  • 10 posts

Posted 27 June 2012 - 07:40 PM

Thank you, so much. This worked flawlessly. And it leaves console completely open which helps a lot. Thanks for the help Mystic!

#8 TheWoWClown

  • New Members
  • 10 posts

Posted 27 June 2012 - 07:44 PM

I'm really sorry I have one more question, is there a way to make it update every few seconds or so, so I can keep a real time monitor?

local side = "top" -- the side the monitor is on
if peripheral.isPresent(side) and peripheral.getType(side) == "monitor" then
  term.redirect(peripheral.wrap(side))
else
  print("Monitor not found")
  return
end
print("Redstone output status list.")
for _,side in ipairs(rs.getSides()) do
  print(side, " = ", (rs.getOutput(side) and "On") or "Off") -- print "On" and "Off" instead of true/false
end
term.restore()

Thanks so much, I know this is really annoying, but I am really new and am trying to learn as much as I can.

#9 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 27 June 2012 - 08:00 PM

Adding a simple while loop and using sleep should be enough:
local side = "top" -- the side the monitor is on
local nTime = 3 -- time between updates, in seconds

if peripheral.isPresent(side) and peripheral.getType(side) == "monitor" then
  term.redirect(peripheral.wrap(side))
else
  print("Monitor not found")
  return
end

local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end

while true do
  clear()
  print("Redstone output status list.")
  for _,side in ipairs(rs.getSides()) do
	print(side, " = ", (rs.getOutput(side) and "On") or "Off") -- print "On" and "Off" instead of true/false
  end
  sleep(nTime)
end


#10 TheWoWClown

  • New Members
  • 10 posts

Posted 27 June 2012 - 08:10 PM

The code freezes up my computer and does not let me use it. Though, the updater works. I tested this by changing the code to input, and it updates when it has a new input. I think I might be able to us this if I branch redstone off of all sides and string them to the corresponding sides of a machine meant for recording inputs. If you can't fix the code I can just do this.

#11 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 27 June 2012 - 08:16 PM

Well, you would need parallel if you want to use the computer while running the program.
I think this should work:
local side = "top" -- the side the monitor is on
local nTime = 3 -- time between updates, in seconds

local mon
if peripheral.isPresent(side) and peripheral.getType(side) == "monitor" then
  mon = peripheral.wrap(side)
else
  print("Monitor not found")
  return
end

local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end

local function run()
  while true do
    term.redirect(mon)
    clear()
    print("Redstone output status list.")
    for _,side in ipairs(rs.getSides()) do
      print(side, " = ", (rs.getOutput(side) and "On") or "Off") -- print "On" and "Off" instead of true/false
    end
    term.restore()
    sleep(nTime)
  end
end

parallel.waitForAny(run, function() shell.run("shell") end)

And if you want it for monitoring intput, use this one:
local side = "top" -- the side the monitor is on

local mon
if peripheral.isPresent(side) and peripheral.getType(side) == "monitor" then
  mon = peripheral.wrap(side)
else
  print("Monitor not found")
  return
end

local function clear()
  term.clear()
  term.setCursorPos(1, 1)
end

local function run()
  while true do
    term.redirect(mon)
    clear()
    print("Redstone input status list.")
    for _,side in ipairs(rs.getSides()) do
      print(side, " = ", (rs.getInput(side) and "On") or "Off") -- print "On" and "Off" instead of true/false
    end
    term.restore()
    os.pullEvent("restone")
  end
end

parallel.waitForAny(run, function() shell.run("shell") end)
It updates every time there's a change in redstone input.

#12 Dirkus7

  • Members
  • 148 posts
  • Locationthe Netherlands

Posted 27 June 2012 - 09:01 PM

View PostTheWoWClown, on 27 June 2012 - 07:14 PM, said:

Okay I am sorry to waste your time again, but I split it into two programs so that the status check would actually be useful. Now, I have s monitor above my computer, and was wondering how I would be able to make the status updates project right onto the monitor so that I can see it without going into the console. The new code for the status update is
print("Redstone output status list.")
for _,side in ipairs(rs.getSides()) do
  print(side, " = ", rs.getOutput(side))
end
I want it to project onto a screen, and will probably install it on it's own computer so that I can use my main computer for other things. If you could please help me again it would be amazing. And I am sorry for wasting your time at first Dirkus.
No problem dude, i hope you understand that you can't compare false with true :P/> That was just my point

#13 TheWoWClown

  • New Members
  • 10 posts

Posted 27 June 2012 - 10:44 PM

Thank you everyone! The new script works perfectly with what I want it to do.
The help was wonderful.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users