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

Problem with colors on terminal

Started by Xixili, 02 December 2013 - 12:42 PM
Xixili #1
Posted 02 December 2013 - 01:42 PM
Hello everyone,

I try to make a colored security lock but I do something wrong and I dont know what that is.

What I try to make:
The first 2 lines need to be orange background with white text.
from the 3th line needs to be a white background with black text.

and then the last 2 lines on the bottom need to be orange again.

Many thanks if you can help me


os.pullEvent = os.pullEventRaw
local standby = 5
local side = "left"
local password = "xixili"
term.clear()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.orange)
term.clear()
term.setCursorPos(12,1)
term.setTextColor(colors.white)
print("Security Panel")
term.clear()
term.setCursorPos(1,3)
term.setBackgroundColor(colors.white)
term.clear()
term.setCursorPos(1,4)
write("Password: ")
local input = read("*")
if input == password then
term.clear()
term.setCursorPos(1,4)
print("Correct")
rs.setOutput(side,true)
sleep(5)
rs.setOutput(side,false)
os.reboot()
else
term.clear()
term.setCursorPos(1,4)
print("Wrong Password")
sleep(2)
os.reboot()
end
LBPHacker #2
Posted 02 December 2013 - 02:13 PM
term.clear fills the entire screen with the current background color. Call it only when you want to clear the screen. I fixed up everything a little bit.[namedspoiler=I'm sure the code is self-explanatory][code]os.pullEvent = os.pullEventRaw
local standby = 5
local side = "left"
local password = "xixili"

– we'll put the "Security Panel" text exactle in the middle
– and this'll help us fill the last row with orange
local width, height = term.getSize()

term.setCursorPos(1, 1)
term.setBackgroundColor(colors.white)
term.clear() – fill the screen with white

term.setTextColor(colors.white)
term.setBackgroundColor(colors.orange)
term.clearLine() – that will fill the first row of the screen with orange

term.setCursorPos(1, height)
term.clearLine() – ditto, but the cursor is on the last row, so will be the filling

local text = "Security Panel"
term.setCursorPos(math.floor((width - #text) / 2), 1)
– this is the native text writing method from the term API
– it writes text where the cursor currently is
term.write(text)

term.setTextColor(colors.black)
term.setBackgroundColor(colors.white)
term.setCursorPos(3, 3)
term.write("Password: ") – write the Password message
local input = read("*")

term.setCursorPos(3, 5) – took this out of the IF block - it happens anyway
if input == password then
term.write("Correct")
rs.setOutput(side, true)
sleep(5)
rs.setOutput(side, false)
else
term.write("Wrong Password")
sleep(2)
end
os.reboot()

EDIT: Line 22: Forgot the length operator (#)…
Edited on 02 December 2013 - 01:16 PM
Xixili #3
Posted 02 December 2013 - 02:19 PM
term.clear fills the entire screen with the current background color. Call it only when you want to clear the screen. I fixed up everything a little bit.[namedspoiler=I'm sure the code is self-explanatory][code]os.pullEvent = os.pullEventRaw
local standby = 5
local side = "left"
local password = "xixili"

– we'll put the "Security Panel" text exactle in the middle
– and this'll help us fill the last row with orange
local width, height = term.getSize()

term.setCursorPos(1, 1)
term.setBackgroundColor(colors.white)
term.clear() – fill the screen with white

term.setTextColor(colors.white)
term.setBackgroundColor(colors.orange)
term.clearLine() – that will fill the first row of the screen with orange

term.setCursorPos(1, height)
term.clearLine() – ditto, but the cursor is on the last row, so will be the filling

local text = "Security Panel"
term.setCursorPos(math.floor((width - #text) / 2), 1)
– this is the native text writing method from the term API
– it writes text where the cursor currently is
term.write(text)

term.setTextColor(colors.black)
term.setBackgroundColor(colors.white)
term.setCursorPos(3, 3)
term.write("Password: ") – write the Password message
local input = read("*")

term.setCursorPos(3, 5) – took this out of the IF block - it happens anyway
if input == password then
term.write("Correct")
rs.setOutput(side, true)
sleep(5)
rs.setOutput(side, false)
else
term.write("Wrong Password")
sleep(2)
end
os.reboot()

EDIT: Line 22: Forgot the length operator (#)…

Its a long time ago that I worked with computercraft so I need to learn it all over again :(/>

There is an error on line 22
1:22: attempt to perform arithmetic on string
LBPHacker #4
Posted 02 December 2013 - 02:20 PM
-snip-
Even the block you quoted states that I forgot the # operator from line 22…

EDIT: Aaaaaand as an addition, I forgot that you wanted the orange lines to be two char high. Heck, sorry for that.
Edited on 02 December 2013 - 01:24 PM
Xixili #5
Posted 02 December 2013 - 02:28 PM
-snip-
Even the block you quoted states that I forgot the # operator from line 22…

EDIT: Aaaaaand as an addition, I forgot that you wanted the orange lines to be two char high. Heck, sorry for that.
Thank you very much!
It works!