Jump to content




[Programming] Clearing one line.


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

#1 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 16 September 2012 - 04: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

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 16 September 2012 - 04:25 AM

Yes use something like this.

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

Then do your print or write.

#3 GopherAtl

  • Members
  • 888 posts

Posted 16 September 2012 - 05: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.

#4 Exerro

  • Members
  • 801 posts

Posted 16 September 2012 - 08: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

#5 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 16 September 2012 - 05:26 PM

View Postawsumben13, on 16 September 2012 - 08:54 AM, said:

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?

#6 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 16 September 2012 - 05:31 PM

View Postawsumben13, on 16 September 2012 - 08:54 AM, said:

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.

#7 hego555

  • Members
  • 89 posts

Posted 16 September 2012 - 07: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


#8 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 16 September 2012 - 07:40 PM

View Postdlcruz129, on 16 September 2012 - 05:26 PM, said:

View Postawsumben13, on 16 September 2012 - 08:54 AM, said:

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.

#9 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 16 September 2012 - 08:15 PM

View PostLyqyd, on 16 September 2012 - 07:40 PM, said:

View Postdlcruz129, on 16 September 2012 - 05:26 PM, said:

View Postawsumben13, on 16 September 2012 - 08:54 AM, said:

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)






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users