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

[Programming] Clearing one line.

Started by Dlcruz129, 16 September 2012 - 03:11 AM
Dlcruz129 #1
Posted 16 September 2012 - 05:11 AM
Hi.

I have a computer that checks if my IC2 Solar Panels are online with an EU-detector cable and an
rs.getInput
. I wanted to make it update automatically, so i used a
while true do
loop. However, it spammed my screen with "Solar Panels Online". I have other info on the screen, so I can't just have the loop clear the screen. Is there any way to make it "update" that one line? Maybe have it clear that line?

Thanks!

dlcruz129
Luanub #2
Posted 16 September 2012 - 05:25 AM
Yes use something like this.


term.setCursorPos(1,3)
term.clearLine()

Then do your print or write.
GopherAtl #3
Posted 16 September 2012 - 06:00 AM
when you're using parts of the screen to display info rather than printing at the bottom and scrolling like the shell window, term.write() is usually preferable to print, as it doesn't do the n, so you can write to the last line without everything getting moved up a line.
Exerro #4
Posted 16 September 2012 - 09:54 AM
i use a function like this:

function clearLine(nLine)
term.setCursorPos(1,nLine)
term.write("												  ") -- 50 spaces (i might have misse one or two)
end
then you would use clearLine(10) and it would clear line 10
hope i helped
Dlcruz129 #5
Posted 16 September 2012 - 06:26 PM
i use a function like this:

function clearLine(nLine)
term.setCursorPos(1,nLine)
term.write("												  ") -- 50 spaces (i might have misse one or two)
end
then you would use clearLine(10) and it would clear line 10
hope i helped

Thanks! Gonna try it right now.

EDIT: Just tried it. Started working perfectly, but after a few seconds it printed "Too long without Yielding". How do I fix this bug? I still want it to update live if my solar panels are on/offline

EDIT 2: The console lets you type "open" or "console" to get to my mfsu and use the sensors. I want people to be able to type while it auto-updates. Is that possible?
Cranium #6
Posted 16 September 2012 - 06:31 PM
i use a function like this:

function clearLine(nLine)
term.setCursorPos(1,nLine)
term.write("												  ") -- 50 spaces (i might have misse one or two)
end
then you would use clearLine(10) and it would clear line 10
hope i helped
There is actually an existing function for this. term.clearLine() clears the currently written to line.
hego555 #7
Posted 16 September 2012 - 08:07 PM
I think a sleep function with a loop would work!


while true do
--CHECK STATUS
print ("Solor Panels: "+status)
sleep(5)
shell.run("clear")
end
Lyqyd #8
Posted 16 September 2012 - 08:40 PM
i use a function like this:

function clearLine(nLine)
term.setCursorPos(1,nLine)
term.write("												  ") -- 50 spaces (i might have misse one or two)
end
then you would use clearLine(10) and it would clear line 10
hope i helped

Thanks! Gonna try it right now.

EDIT: Just tried it. Started working perfectly, but after a few seconds it printed "Too long without Yielding". How do I fix this bug? I still want it to update live if my solar panels are on/offline

EDIT 2: The console lets you type "open" or "console" to get to my mfsu and use the sensors. I want people to be able to type while it auto-updates. Is that possible?

Yes, this is possible. You'd want to copy the read function from bios.lua, then modify it to listen for a timer event and run the screen-updating code.
MysticT #9
Posted 16 September 2012 - 09:15 PM
i use a function like this:

function clearLine(nLine)
term.setCursorPos(1,nLine)
term.write("												  ") -- 50 spaces (i might have misse one or two)
end
then you would use clearLine(10) and it would clear line 10
hope i helped

Thanks! Gonna try it right now.

EDIT: Just tried it. Started working perfectly, but after a few seconds it printed "Too long without Yielding". How do I fix this bug? I still want it to update live if my solar panels are on/offline

EDIT 2: The console lets you type "open" or "console" to get to my mfsu and use the sensors. I want people to be able to type while it auto-updates. Is that possible?

Yes, this is possible. You'd want to copy the read function from bios.lua, then modify it to listen for a timer event and run the screen-updating code.
Or use parallel.

local function updateScreen()
  while true do
    print("Status: ", getStatus())
    os.pullEvent("redstone") -- if you use redstone to check the status this is better than a timer.
  end
end

local function getUserInput()
  while true do
    local input = read()
    if input == "something" then
	  doSomething()
    end
  end
end

parallel.waitForAny(updateScreen, getUserInput)