Jump to content




Update monitor every 3 seconds


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

#1 Arendium

  • New Members
  • 2 posts

Posted 01 December 2013 - 07:24 AM

Hej i would like to update my monitor every 3 seconds
I have copied some code:

os.startTimer(1)
while true do
term.setCursorPos(3,8)
term.clearLine()
m.write("Hitze: ")
m.write(nR.getHeat())
sleep(2)
os.pullEvent("timer")
os.startTimer(1)
end

But it don't work i don't see anything

My complete code:

local function padLeft(str, w)
  return string.rep(" ", w - #str) .. str
end

local function findPeripheral(_type)
  for _,name in pairs(peripheral.getNames()) do
    if peripheral.getType(name) == _type then
	  return peripheral.wrap(name)
    end
  end
  error("Fehler: ".._type.." Kann nicht gefunden werden!", 0)
end

term.clear()
m = peripheral.wrap("left")
nR = findPeripheral("nuclear_reactor")
term.redirect(m)
m.setTextScale(1)

term.setCursorPos(3,1)
m.setBackgroundColor(colors.green)
print("Ein")
term.setCursorPos(3,2)
m.setBackgroundColor(colors.red)
print("Aus")
m.setBackgroundColor(colors.black)
term.setCursorPos(3,8)
m.write("Hitze: ")
m.write(nR.getHeat())
term.setCursorPos(3,9)
m.write("Von: ")
m.write(nR.getMaxHeat())
while true do
event,side,x,y = os.pullEvent()
  if event == "monitor_touch" then
    if y == 1 then
    term.setCursorPos(3,4)
    term.clearLine()
    m.setBackgroundColor(colors.green)
    print("   ")
    redstone.setOutput("back",true)
    end
    if y == 2 then
    term.setCursorPos(3,4)
    term.clearLine()
    m.setBackgroundColor(colors.red)
    print("   ")
    redstone.setOutput("back",false)
    end
    term.setBackgroundColor(colors.black)
  end
end
os.startTimer(1)
while true do
term.setCursorPos(3,8)
term.clearLine()
m.write("Hitze: ")
m.write(nR.getHeat())
sleep(2)
os.pullEvent("timer")
os.startTimer(1)
end


#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 01 December 2013 - 10:37 AM

Don't copy code you don't understand. That code doesn't make any sense. You will want to do something along these lines:
while true do
  --#Update the monitor here
  sleep(3)
end

It's as simple as that.

#3 Arendium

  • New Members
  • 2 posts

Posted 01 December 2013 - 11:10 AM

That don't work it don't update in the reactor there is many heat but not at the monitor
my complete code:
(Update is at the end)
local function padLeft(str, w)
  return string.rep(" ", w - #str) .. str
end

local function findPeripheral(_type)
  for _,name in pairs(peripheral.getNames()) do
    if peripheral.getType(name) == _type then
	  return peripheral.wrap(name)
    end
  end
  error("Fehler: ".._type.." Kann nicht gefunden werden!", 0)
end

term.clear()
m = peripheral.wrap("left")
nR = findPeripheral("nuclear_reactor")
term.redirect(m)
m.setTextScale(1)

term.setCursorPos(3,1)
m.setBackgroundColor(colors.green)
print("Ein")
term.setCursorPos(3,2)
m.setBackgroundColor(colors.red)
print("Aus")
m.setBackgroundColor(colors.black)
term.setCursorPos(3,8)
m.write("Hitze: ")
m.write(nR.getHeat())
term.setCursorPos(3,9)
m.write("Von: ")
m.write(nR.getMaxHeat())
while true do
event,side,x,y = os.pullEvent()
  if event == "monitor_touch" then
    if y == 1 then
    term.setCursorPos(3,4)
    term.clearLine()
    m.setBackgroundColor(colors.green)
    print("   ")
    redstone.setOutput("back",true)
    end
    if y == 2 then
    term.setCursorPos(3,4)
    term.clearLine()
    m.setBackgroundColor(colors.red)
    print("   ")
    redstone.setOutput("back",false)
    end
    term.setBackgroundColor(colors.black)
  end
end
while true do
    term.setCursorPos(3,8)
    term.clearLine()
    m.write("Hitze: ")
    m.write(nR.getHeat())
    sleep(3)
end


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 01 December 2013 - 04:23 PM

while true do -- This will loop as long as "true" is true (ie indefinitely).
  print("1")
end
while true do -- This code won't begin, as the code above it won't stop.
  print("2")
end

Assuming you want the "monitor_touch" event stuff, forget about sleep and use something like:

local myTimer = os.startTimer(1)
while true do
  event,side,x,y = os.pullEvent()
  if event == "monitor_touch" then
    -- Stuff
  elseif event == "timer" and side == myTimer then
    -- More stuff.
    myTimer = os.startTimer(1)
  end
end

Edited by Bomb Bloke, 01 December 2013 - 04:26 PM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users