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

i cant figure out this error

Started by jonathonrox, 27 April 2012 - 01:34 AM
jonathonrox #1
Posted 27 April 2012 - 03:34 AM
so i cant figure out the errors im getting. it would give me errors like: "bios:25: bad argument: double expected, got nil" and "test:28: attempt to perform arithmetic __addon string and number" and maybe others that i havent found yet. could you please help me with this? this is my first big program ive made.
here is a link to my program im making http://pastebin.com/x0qgAUj3

and here is the code



function timer(fa)
for f = 1, fa do
  term.clear()
  term.setCursorPos(4,8)
  print("You have been locked out for "..tostring(fa-f).." seconds.")
  sleep(1)
end
end

a=0
repeat
term.clear()
term.setCursorPos(1,1)
print("|----------------------------|")							
print("|	(Enter the password)	|")
print("|----------------------------|")
print("|							|")
print("|----------------------------|")
print("[Q][W][E][R][T][Y][U][I][O][P]")
print(" [a][s][d][f][g][h][j][k][l]")
print("	[z][x][c][v][b][n][m]")
term.setCursorPos(2,4)

  i=read("*")
if i ~= "pass" then
  local x, y=term.getCursorPos()
  term.setCursorPos(x, y)
  print("WRONG!")
  sleep(.4)
  a=a+1
end

if a == 4 then
	term.clear()
  term.setCursorPos(1,1)
  print("Did you forget your password?")
	local n=1
while true do
  local x, y=term.getCursorPos()
  term.clearLine()
if n==1 then write(">YES<   NO") else write(" YES   >NO<") end
  term.setCursorPos(x, y)
a, b=os.pullEvent()
while a~="key" do a, b=os.pullEvent() end
  if b==203 and n==2 then n=1 end
  if b==205 and n==1 then n=2 end
  if b==28 then print("") break end
end
  if n==1 then
   print("password hint: the usual")
   sleep(4)
  elseif n==2 then
   print("try again, but dont mess up otherwise your gonna get locked out")
   sleep(4)
   break
end

elseif a == 5 then
  timer(101)
elseif a > 5 then
  timer(151)
end
until i == "pass"
-- put whatever you want it to do if the password is correct right here
os.reboot()
Luanub #2
Posted 27 April 2012 - 03:52 AM
You probably just need to declare a prior to using it. Do a = 0 near the top of the code.

You also use the var a in a couple of places for different thing and none of them are local to a function so they are going to conflict with each other. You will need to change one of them to something else.


a=a+1

a, b=os.pullEvent()
while a~="key" do a, b=os.pullEvent() end



This is also pointless as it is just going to leave the cursor where it currently is.

 local x, y=term.getCursorPos()
  term.setCursorPos(x, y)


And lastly you need to end a while loop with and end and not an until, until is for a repeat loop. Correct while syntax for what you are trying to do is.

while i ~= "pass"
code here
end

Or just use a repeat loop

repeat
code
until i == "pass"
EmTeaKay #3
Posted 27 April 2012 - 03:56 AM
On line 25 it should be
 if i ~== "pass" then

=
This means that it will assign something.
==
This means it will read the assigned thing.
cant_delete_account #4
Posted 27 April 2012 - 03:57 AM
On line 25 it should be
 if i ~== "pass" then

=
This means that it will assign something.
==
This means it will read the assigned thing.
Wrong, the ~= means not equal, it's not ~==.
Alternatively, you could use if not i == "pass" then
kamnxt #5
Posted 27 April 2012 - 01:59 PM
In your code you want to get a key. You used
a, b = os.pullEvent()
while a ~= "key" do a, b = os.pullEvent() end 
If you only wait for one type of events, you can use os.pullEvent("eventType").

a,b = os.pullEvent("key")
jonathonrox #6
Posted 28 April 2012 - 06:28 AM
ok i got the code done and working perfectly. here's the pastebin for it: http://pastebin.com/sd51eY5r

and here is the code


choice=0
z=0
function timer(fa)
for f = 1, fa do
  term.clear()
  term.setCursorPos(4,8)
  print("You have been locked out for "..tostring(fa-f).." seconds.")
  sleep(1)
end
end
repeat
term.clear()
term.setCursorPos(1,1)
print("|----------------------------|")						   
print("|    (Enter the password)    |")
print("|----------------------------|")
print("|						    |")
print("|----------------------------|")
print("[Q][W][E][R][T][Y][U][I][O][P]")
print(" [a][s][d][f][g][h][j][k][l]")
print("    [z][x][c][v][b][n][m]")
term.setCursorPos(2,4)
  i=read("*")
if i ~= "pass" then
  print("WRONG!")
  sleep(.4)
  choice=choice+1
end
if choice == 4 and z == 0 then
    term.clear()
  term.setCursorPos(1,1)
  print("Did you forget your password?")
    local n=1
while true do
  local x, y=term.getCursorPos()
  term.clearLine()
if n==1 then write(">YES<   NO") else write(" YES   >NO<") end
  term.setCursorPos(x, y)
a, b=os.pullEvent()
while a~="key" do a, b=os.pullEvent() end
  if b==203 and n==2 then n=1 end
  if b==205 and n==1 then n=2 end
  if b==28 then print("") break end
end
  if n==1 then
   print("password hint: the usual")
   sleep(4)
   z=z+1
  elseif n==2 then
   print("try again, but dont mess up otherwise your gonna get locked out")
   sleep(4)
   z=z+1
end
elseif choice == 5 then
  timer(101)
elseif choice > 5 then
  timer(151)
end
until i == "pass"
-- put whatever you want it to do if the password is correct right here
os.reboot()

you can try it out. its really cool.