Jump to content




term.cursorpos manipulation overwriting problems


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

#1 Doyle3694

  • Members
  • 815 posts

Posted 19 December 2012 - 04:48 AM

Hey guys, I'm making my own kinda OS/Program, which has a cool menu and so on... the problem is, I want my header, which is takes 2 lines, to always be visible. tried first
if true then
   local sneaky = term.setCursorPos
   function term.setCursorPos(x,y)
	  sneaky(x,y+2)
   end
end
which didn't work.
Everything I wrote looked all messy and stuff, which I didn't want. I realised it was because print uses write which uses term.getCursorPos, which would give something completely oftrack. It gave 2 lines of space inbetween each row.

So I tried
if true then
   local sneaky2 = term.getCursorPos
   function term.getCursorPos()
	  x,y = sneaky2()
	  return x,y+2
   end
   local sneaky = term.setCursorPos
   function term.setCursorPos(x,y)
	  sneaky(x,y+2)
   end
end

which really, just gave me 1 more line of space inbetween every line.
So I added 1 more function:
if true then
   local sneaky3 = term.getSize
   function term.getSize()
	  w,h = sneaky3()
	  return w,h-2
   end
   local sneaky2 = term.getCursorPos
   function term.getCursorPos()
	  x,y = sneaky2()
	  return x,y+2
   end
   local sneaky = term.setCursorPos
   function term.setCursorPos(x,y)
	  sneaky(x,y+2)
   end
end
and now, really messed up lines

So now I'm out of ideas. My code is currently 266 lines long, so i would avoid posting it, and I dont think the code makes this, since it worked before these functions.

Problem now fixed!
here is fixed code, for everyone to learn from ^^
if true then
   local sneaky3 = term.getSize
   function term.getSize()
	  w,h = sneaky3()
	  return w,h-2
   end
   local sneaky2 = term.getCursorPos
   function term.getCursorPos()
	  x,y = sneaky2()
	  return x,y-2
   end
   local sneaky = term.setCursorPos
   function term.setCursorPos(x,y)
	  sneaky(x,y+2)
   end
end


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 19 December 2012 - 04:51 AM

You forgot to make it actually call sneaky3. You should probably be subtracting two before returning the results of sneaky2.

#3 Doyle3694

  • Members
  • 815 posts

Posted 19 December 2012 - 04:57 AM

yeah I saw I forgot the call, edited and made the fix, and posted the new problem. and for sneaky2, mean I should have -2 rather than +2?

EDIT: Thanks dude, that did the job! Edited code to be correct.





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users