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

Window Error

Started by SNWLeader, 07 November 2014 - 07:12 AM
SNWLeader #1
Posted 07 November 2014 - 08:12 AM
I am trying to make a locking program for a Pocket Computer.

i get this:

"window:248: bad argument : double expected, got nil"

This is my coding

step = 5
password = "password"
overide = "overide"
local function ClearLines()
term.setCursorPos(1,1)
term.clearLine()
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,3)
term.clearLine()
term.setCursorPos(1,4)
term.clearLine()
term.setCursorPos(1,5)
term.clearLine()
term.setCursorPos(1,6)
term.clearLine()
term.setCursorPos(1.7)
term.clearLine()
term.setCursorPos(1,1)
end
local function LockScreen()
while true do
term.clear()
term.setCursorPos(1,20)
print("Password Protection: v1.1")
term.setCursorPos(1,1)
print("Please Enter Password.")
term.setCursorPos(1,3)
write("?:  ")
input = read("*")
if input == password then
break
else
ClearLines()
print("Sorry, Incorrect Password")
step = step + 1
sleep(1)
end
if step == 5 then
ClearLines()
print("You have Exceeded your tries")
sleep(2)
print("Computer Shutting Down")
os.shutdown()
end
end
term.clear()
term.setCursorPos(1,1)
textutils.slowWrite("Pad is Starting")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(2)
print("")
print("Boot Complete")
sleep(1)
term.clear()
term.setCursorPos(1,1)
end
LockScreen()
DannySMc #2
Posted 07 November 2014 - 10:29 AM
Having a look, hang on!

I am trying to make a locking program for a Pocket Computer.

i get this:

"window:248: bad argument : double expected, got nil"

This is my coding

step = 5
password = "password"
overide = "overide"
local function ClearLines()
term.setCursorPos(1,1)
term.clearLine()
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,3)
term.clearLine()
term.setCursorPos(1,4)
term.clearLine()
term.setCursorPos(1,5)
term.clearLine()
term.setCursorPos(1,6)
term.clearLine()
term.setCursorPos(1.7)
term.clearLine()
term.setCursorPos(1,1)
end
local function LockScreen()
while true do
term.clear()
term.setCursorPos(1,20)
print("Password Protection: v1.1")
term.setCursorPos(1,1)
print("Please Enter Password.")
term.setCursorPos(1,3)
write("?:  ")
input = read("*")
if input == password then
break
else
ClearLines()
print("Sorry, Incorrect Password")
step = step + 1
sleep(1)
end
if step == 5 then
ClearLines()
print("You have Exceeded your tries")
sleep(2)
print("Computer Shutting Down")
os.shutdown()
end
end
term.clear()
term.setCursorPos(1,1)
textutils.slowWrite("Pad is Starting")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(2)
print("")
print("Boot Complete")
sleep(1)
term.clear()
term.setCursorPos(1,1)
end
LockScreen()

GOT IT!
In your ClearLines() function you have put:
term.setCursorPos(1.7)
where it should be:
term.setCursorPos(1,7)

You put a fullstop instead of a comma, checked it and it works!

Having a look, hang on!

I am trying to make a locking program for a Pocket Computer.

i get this:

"window:248: bad argument : double expected, got nil"

This is my coding

step = 5
password = "password"
overide = "overide"
local function ClearLines()
term.setCursorPos(1,1)
term.clearLine()
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,3)
term.clearLine()
term.setCursorPos(1,4)
term.clearLine()
term.setCursorPos(1,5)
term.clearLine()
term.setCursorPos(1,6)
term.clearLine()
term.setCursorPos(1.7)
term.clearLine()
term.setCursorPos(1,1)
end
local function LockScreen()
while true do
term.clear()
term.setCursorPos(1,20)
print("Password Protection: v1.1")
term.setCursorPos(1,1)
print("Please Enter Password.")
term.setCursorPos(1,3)
write("?:  ")
input = read("*")
if input == password then
break
else
ClearLines()
print("Sorry, Incorrect Password")
step = step + 1
sleep(1)
end
if step == 5 then
ClearLines()
print("You have Exceeded your tries")
sleep(2)
print("Computer Shutting Down")
os.shutdown()
end
end
term.clear()
term.setCursorPos(1,1)
textutils.slowWrite("Pad is Starting")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(1)
write(".")
sleep(2)
print("")
print("Boot Complete")
sleep(1)
term.clear()
term.setCursorPos(1,1)
end
LockScreen()

GOT IT!
In your ClearLines() function you have put:
term.setCursorPos(1.7)
where it should be:
term.setCursorPos(1,7)

You put a fullstop instead of a comma, checked it and it works!

for a better clear screen try this:

function resetScreen()
term.clear()
term.setCursorPos(1,1)
term.setTextColour(colours.white)
term.setBackgroundColour(colours.black)
i = 1
repeat
  term.setCursorPos(1,i)
  y = 1
  repeat
   term.setCursorPos(y,i)
   print(" ")
   y = y + 1
  until y >= 51
  i = i + 1
until i >= 19
end
Edited on 07 November 2014 - 09:30 AM
MKlegoman357 #3
Posted 07 November 2014 - 03:18 PM
for a better clear screen try this:

function resetScreen()
term.clear()
term.setCursorPos(1,1)
term.setTextColour(colours.white)
term.setBackgroundColour(colours.black)
i = 1
repeat
  term.setCursorPos(1,i)
  y = 1
  repeat
   term.setCursorPos(y,i)
   print(" ")
   y = y + 1
  until y >= 51
  i = i + 1
until i >= 19
end

Well, first, a for loop was created to make these kind of loops easier. Second, to clear the screen with only spaces and one background color you can just use term.clear(), after setting the background color. Third, you might get the screen size using term.getSize(), and because the OP is using a Pocket Computer your code wouldn't clear the whole screen.

So these were some things I found that were wrong about your posted code. And please don't take this rough or anything, we programmers always learn something new everyday :)/>