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

[Lua][Error] bios: 206: [string "startup"]:6: '=' expected What do?

Started by Demolisha12, 30 April 2012 - 06:42 AM
Demolisha12 #1
Posted 30 April 2012 - 08:42 AM
I don't know what to do any help would be appreciated


local side = "back"
local password = "password"
local lock ="lock"
start
rs.setOutput(side,true)
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == (password)
term.clear()
term.setCursorPos(1,1)
print("Password correct!")
rs.setOutput(side,true)
  mid
  local input = read
  if input == lock
   term.clear()
   term.setCursorPos(1,1)
   rs.setOutput(side,true)
   print ("Locking.")
   sleep 1
   print ("Locking..")
   sleep 1
   print ("Locking...")
   sleep 1
   goto start
  else
   goto Mid
else
term.clear()
term.setCursorPos(1,1)
print("Password incorrect!")
goto start
end
Luanub #2
Posted 30 April 2012 - 08:45 AM
Lua does not support the goto function. You instead need to use functions and call them.


function start()
insert code here
end

start()  -- calls the function
Demolisha12 #3
Posted 30 April 2012 - 08:49 AM
ah i see, i read somewhere that it did
Luanub #4
Posted 30 April 2012 - 08:52 AM
Lua 5.2 does support goto. The LuaJ 5.1 that Dan uses for CC does not.

It's probably better to use functions anyway.
Demolisha12 #5
Posted 30 April 2012 - 09:25 AM
okay i changed it a bit but now it won't open

local side = "back"
local password = "password"
local lock ="lock"
function start()
rs.setOutput(side,true)
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == (password)
then
term.clear()
term.setCursorPos(1,1)
print("Password correct!")
rs.setOutput(side,true)
else
term.clear()
term.setCursorPos(1,1)
print("Password incorrect!")
start()
end
  function mid()
  local input = read
  if input == lock
   then
   term.clear()
   term.setCursorPos(1,1)
   rs.setOutput(side,true)
   print("Locking.")
   sleep(1)
   print("Locking..")
   sleep(1)
   print("Locking...")
   sleep(1)
   start()
  else
   Mid()
  end
end
end
Demolisha12 #6
Posted 30 April 2012 - 09:27 AM
i don't get any errors, nothing happens whatsoever
Demolisha12 #7
Posted 30 April 2012 - 09:31 AM
do i have to call start() just before the final end?
Luanub #8
Posted 30 April 2012 - 10:06 AM
You need to call it after the function like I did in the small example, that way Lua has the function loaded. Lua is also case sensitive so mid() and Mid() are not the same, its also better to not create functions within functions even then it is possible.

Try doing something like this.. I also fixed a couple of other errors, added comments in the script for them
Spoiler

local side = "back"
local password = "password"
local lock ="lock"

function mid()
  while true do -- added while loop
  term.clear()
  term.setCursorPos(1,1)
  write("Enter Command: ") -- added so there was something to indicate something needed to be entered
  local input = read() -- added ()'s
  if input == lock then
   term.clear()
   term.setCursorPos(1,1)
   rs.setOutput(side,true)
   print("Locking.")
   sleep(1)
   print("Locking..")
   sleep(1)
   print("Locking...")
   sleep(1)
   start()
   break -- break the while loop
  else
   print ("Invalid Command, try again") -- incase invalid command entered
   sleep(1)
  end
end
end

function start()
while true do
rs.setOutput(side,true)
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local input = read("*")
if input == (password)
then
term.clear()
term.setCursorPos(1,1)
print("Password correct!")
rs.setOutput(side,true)
mid()
break -- stop the loop
else
term.clear()
term.setCursorPos(1,1)
print("Password incorrect!")
sleep(1) -- added so you will see the error message
end
end
end

start()