Can anyone tell me why?
local function loginScript()
paintutils.drawLine(10,6,40,6, colors.blue)
term.setCursorPos(10, 6)
term.setTextColor(colors.white)
term.setBackgroundColor(colors.blue)
write("Please login")
for i = 1, 7 do
paintutils.drawLine(10, 6 + i, 40, 6 + i, colors.lightGray)
end
local loginObjects = {
{name = "Username:",
nameX = 11,
nameY = 9,
color = colors.black,
BGcolor = colors.lightGray},
{name = "Username: ",
nameX = 21,
nameY = 9,
color = colors.white,
BGcolor = colors.white},
{name = "Password:",
nameX = 11,
nameY = 11,
color = colors.black,
BGcolor = colors.lightGray},
{name = "Password: ",
nameX = 21,
nameY = 11,
color = colors.white,
BGcolor = colors.white}
}
for i = 1, #loginObjects do
term.setCursorPos(loginObjects[i].nameX, loginObjects[i].nameY)
term.setTextColor(loginObjects[i].color)
term.setBackgroundColor(loginObjects[i].BGcolor)
write(loginObjects[i].name)
end
term.setCursorPos(22, 9)
while true do
username = limitRead(16)
if username ~= "TEMP_USER" then
break
end
end
term.setCursorPos(22, 11)
while true do
password = limitRead(16, "*")
if password ~= "TEMP_PASSWORD" then
break
end
end
local response = http.post(
"http://pastebin.com/api/api_login.php",
"api_dev_key="..devKey.."&"..
"api_user_name="..textutils.urlEncode(username).."&"..
"api_user_password="..textutils.urlEncode(password)
)
local badRequests = {
"Bad API request, invalid login",
"Bad API request, account not active"
}
if response then
local sReponse = response.readAll()
response.close()
term.setCursorPos(1,y-1)
print(sResponse)
if sResponse == badRequests[1] then
term.setCursorPos(11,7)
term.setBackgroundColor(colors.lightGray)
term.setTextColor(colors.red)
write("Invalid login!")
end
end
end
This is just the login function. It's the only thing that is giving me trouble right now.EDIT: Forgot to add my limitRead() function…. just in case you guys want to run the function.
-- limit read function
local function limitRead(limX, rChar)
term.setCursorBlink(true)
local origX, origY = term.getCursorPos()
local returnString = ""
while true do
local xPos, yPos = term.getCursorPos()
local event, p1, p2 = os.pullEvent()
if event == "char" then
returnString = returnString..p1
if not rChar then
if not limX then
term.setTextColor(colors.blue)
write(p1)
else
if string.len(returnString) >= limX then
term.setTextColor(colors.blue)
term.setCursorPos(origX, origY)
write(string.sub(returnString, (string.len(returnString)-limX)+1))
elseif string.len(returnString) < limX then
term.setTextColor(colors.blue)
write(p1)
end
end
else
if not limX then
term.setTextColor(colors.blue)
write(rChar)
else
if string.len(returnString) >= limX then
term.setTextColor(colors.blue)
term.setCursorPos(origX, origY)
write(string.rep(rChar, limX))
elseif string.len(returnString) < limX then
term.setTextColor(colors.blue)
write(rChar)
end
end
end
elseif event == "key" and p1 == 14 then --backspace
returnString = string.sub(returnString, 1, (string.len(returnString))-1)
term.setCursorPos(xPos-1,yPos)
term.setTextColor(colors.blue)
write(" ")
term.setCursorPos(origX, origY)
if string.len(returnString) >= limX then
if not rChar then
term.setTextColor(colors.blue)
write(string.sub(returnString, (string.len(returnString)-limX)+1))
else
term.setTextColor(colors.blue)
write(string.rep(rChar,limX))
end
else
if not rChar then
term.setTextColor(colors.blue)
write(returnString)
else
term.setTextColor(colors.blue)
write(string.rep(rChar, string.len(returnString)))
end
end
elseif event == "key" and p1 == 15 then --tab
break
elseif event == "key" and p1 == 28 then --enter
break
end
end
term.setCursorBlink(false)
return returnString
end