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

please help me

Started by KaMiKaZeTo, 31 May 2012 - 10:18 AM
KaMiKaZeTo #1
Posted 31 May 2012 - 12:18 PM
I have one more problem


When i write something two of the symbols disappears when i write something one is # the other | can i fix that?

Lolgast #2
Posted 31 May 2012 - 02:24 PM
We need the code in order to help you. Now it's impossible to see what's the problem.
Pinkishu #3
Posted 31 May 2012 - 04:34 PM
We need the code in order to help you. Now it's impossible to see what's the problem.

It's what read() does, clears the rest of the line form where the cursor is when you start writing
MysticT #4
Posted 31 May 2012 - 05:33 PM
We need the code in order to help you. Now it's impossible to see what's the problem.

It's what read() does, clears the rest of the line form where the cursor is when you start writing
That's the problem. You could solve this by handling the key presses yourself instead of using read(). You can take the read() code and make a modified version for that, wich takes an argument that limits the input size, so it doesn't write over the whole line.
KaMiKaZeTo #5
Posted 31 May 2012 - 07:19 PM
I can't do it please help me :)/>/>

term.clear()
a = "1"
b = "2"
c = "3"



print(" ################################################")
print(" #											  #")
print(" #			  Lights System v0.1			  #")
print(" #											  #")
print(" #											  #")
print(" #    To turn the lights ON write [1]		   #")
print(" #											  #")
print(" #    To turn the lights OFF write [2]		  #")
print(" #											  #")
print(" #    To enter to the admin menu write [3]	  #")
print(" #											  #")
print(" #											  #")
print(" #				    -------------------	   #")
print(" #    Choose a option:|				 |	   #")
print(" #				    -------------------	   #")
print(" ################################################")

term.setCursorPos(24, 15)
write("")

input = read()
if input == a then
rs.setOutput("back", true)
term.clearLine()
end
input = read()
if input == b then
rs.setOutput("back", false)
end
if input == c then
exit()
end
my_hat_stinks #6
Posted 31 May 2012 - 09:02 PM
try something along the lines of

local working = true
local input = ""
while working do
  local e,p1 = os.pullEvent()

  if e == "key" then
    if p1 == --[[Enter key here]] then
      working = false
      break --Just to make sure
    elseif p1 == --[[Backspace here]] then
      input = string.sub(input,1,-2)
    end
  elseif e == "char" then input=input..p1 end
end
MysticT #7
Posted 31 May 2012 - 09:30 PM
I think you don't need read(), since you just need to select an option, wich is just one key.
Use the char event to get it:

local evt, input = os.pullEvent("char") -- get the input from the user
write(input) -- write it (so the user can see the option he chose)

-- use it
if input == "1" then
...

Also, your calling read() twice, wich would overwrite the first input, and there's some other errors.
Try with this:


local function showGui()
  term.clear()
  term.setCursorPos(1, 1)
  print(" ################################################")
  print(" #											  #")
  print(" #			  Lights System v0.1			  #")
  print(" #											  #")
  print(" #											  #")
  print(" #	To turn the lights ON write [1]		   #")
  print(" #											  #")
  print(" #	To turn the lights OFF write [2]		  #")
  print(" #											  #")
  print(" #	To enter to the admin menu write [3]	  #")
  print(" #											  #")
  print(" #											  #")
  print(" #					-------------------	   #")
  print(" #	Choose a option:|				 |	   #")
  print(" #					-------------------	   #")
  print(" ################################################")
  term.setCursorPos(24, 15)
end

while true do
  showGui()
  local evt, input = os.pullEvent("char")
  write(input)
  if input == "1" then
	rs.setOutput("back", true)
	term.clearLine()
  elseif input == "2" then
	rs.setOutput("back", false)
  elseif input == "3" then
	break
  end
end
KaMiKaZeTo #8
Posted 01 June 2012 - 11:43 AM
Thanks a lot.