Posted 03 May 2014 - 09:53 PM
I was going to use the read function but decided to try and write one myself that auto centers as you type the text. I've come across a weird error that I don't recognize.
[string "term"]:9:bad argument # 2 to '?' (number expected, got no value)
Here's the code.
Just hoping to tap into the vast knowledge of the pros. :)/>
edit: original code spacing didn't show up, fixed now.
[string "term"]:9:bad argument # 2 to '?' (number expected, got no value)
Here's the code.
term.setBackgroundColor(colors.white)
term.clear()
term.setTextColor(colors.white)
sizeX, sizeY = term.getSize()
button = "Start"
term.setCursorPos(math.floor((sizeX - #button) / 2),math.floor((sizeY / 2) + 1))
term.setBackgroundColor(colors.blue)
write(button)
function checkPass(name)
term.clear()
print(name)
end
function getUser()
local askUser = "Please enter your username."
term.setCursorPos(math.floor((sizeX - #askUser) / 2), math.floor((sizeY / 2) - 1))
term.setBackgroundColor(colors.white)
term.setTextColor(colors.blue)
textutils.slowPrint(askUser)
term.setCursorPos(math.floor(sizeX / 2), math.floor(sizeY / 2))
while true do
--term.clearLine()
if user then
term.setCursorPos(math.floor((sizeX - #user) / 2))
else
term.setCursorPos(math.floor(sizeX / 2))
end
print(user)
local event, pressed = os.pullEvent()
if event == "char" then
if user then
user = "user" .. pressed
else
user = pressed
end
elseif event == "key" then
if pressed == 8 then
user = string.sub(user, 1, #user-1)
elseif pressed == 13 then
return user
end
end
end
checkPass(user)
end
function buttonCheck(x,y)
if x > math.floor((sizeX - #button) / 2) and x < math.floor((sizeX + #button) / 2) then
if y == math.floor((sizeY / 2) + 1) then
term.setBackgroundColor(colors.white)
-- term.setCursorPos(1,1)
term.clear()
getUser()
end
end
end
function getClick()
event, t, x, y = os.pullEvent("mouse_click")
buttonCheck(x,y)
end
while true do
getClick()
end
Just hoping to tap into the vast knowledge of the pros. :)/>
edit: original code spacing didn't show up, fixed now.
Edited on 03 May 2014 - 07:59 PM