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

[Question]i get a bios 338 in an if statement plz help

Started by techlevel123, 23 November 2012 - 04:46 AM
techlevel123 #1
Posted 23 November 2012 - 05:46 AM
i made a program to open and close a vault door and i get a " bios:338: [string "startup"]:25: '=' expected ". the code
 os.pullEvent = os.pullEventRaw
local side = "left" -- Change left to whatever side your door / redstone is on, E.G: left, right, front, back, bottom, top. Be sure to leave the "s around it, though
local password = "owncod1811" -- Change bacon to what you want your password to be. Be sure to leave the "s around it though
local exitk = 14
local close = false
local opentime = 4 -- Change 5 to how long (in seconds) you want the redstone current to be on. Don't put "s around it though
while true do
term.clear() -- Clears the screen
term.setCursorPos(1,1) -- Fixes the cursor position
write("Password: ") -- Prints 'Password: ' to the screen
local input = read("=") -- Makes the variable 'input' have the contents of what the user types in the "=" part censors out the password
if input == password then -- Checks if the user inputted the correct password
  term.clear() -- Already explained up top
  term.setCursorPos(1,1)
  print("Password correct!") -- Prints Password correct! to the screen
  rs.setOutput(side,true) -- Output a redstone current to the side you specified
  print("press BACKSPACE to close!")
  while close == false do
  local p1 = os.pullEvent("key")
  if p1 == exitk then
   rs.setOutput(side,false) -- Stop outputting a redstone current
   close = true
   reboot

   else then
  end
end

  elseif input == "debugultrasecurity" then -- checks if the user inputted the code to debug the program
break -- breaks the program

else -- Checks if the user didn't input the correct password
  print("Password incorrect!") -- Prints 'Password incorrect!' to the screen
  sleep(2) -- Waits 2 seconds
end
end
sry for all the comments ;)/>/>
Grim Reaper #2
Posted 23 November 2012 - 07:30 AM
Commenting is actually welcomed among large scripts where other people would like to read and understand the nature of your code, so good job on that!

However, in your program the error occurs on line 23:

reboot
If you're trying to reboot the computer, you'll need to use os.reboot(). When you simply reference a variable without any kind of operator, then the interpreter thinks you're trying to assign a new value to the variable; in this case it would appear you're trying to call a function to reboot the computer.

Also, on line 25:

else then
The 'then' key word will actually throw an error during interpretation. If, elseif, else ladders look something like this in terms of syntax:

if <condition> then
  -- Code
elseif <condition> then
  -- Code
else
  -- Code
end
'else' statements work as a 'catch all' case in which you can handle cases that you did not plan for or do not have any relevance in the desired functionality of your script.

Again, with line 25, you actually don't need that 'else' block. This is because you don't appear to be actually doing anything in the block which renders it unnecessary.
techlevel123 #3
Posted 23 November 2012 - 08:00 AM
Thanks, im not a pro a lua, should probably work on that ;)/>/>
techlevel123 #4
Posted 23 November 2012 - 08:03 AM
the program still dosent work though
it hangs at 17-19
terminal output is

press BACKSPACE to close!
Grim Reaper #5
Posted 23 November 2012 - 08:26 AM
the program still dosent work though
it hangs at 17-19
terminal output is

press BACKSPACE to close!

That is until backspace is pressed and the machine reboots, assuming that he made the changes I had suggested.
techlevel123 #6
Posted 23 November 2012 - 08:32 AM

local side = "left" -- Change left to whatever side your door / redstone is on, E.G: left, right, front, back, bottom, top. Be sure to leave the "s around it, though
local password = "owncod1811" -- Change bacon to what you want your password to be. Be sure to leave the "s around it, though
local exitk = 14
local close = false
local opentime = 4 -- Change 5 to how long (in seconds) you want the redstone current to be on. Don't put "s around it, though
while true do
term.clear() -- Clears the screen
term.setCursorPos(1,1) -- Fixes the cursor position
write("Password: ") -- Prints 'Password: ' to the screen
local input = read("=") -- Makes the variable 'input' have the contents of what the user types in, the "=" part censors out the password
if input == password then -- Checks if the user inputted the correct password
  term.clear() -- Already explained up top
  term.setCursorPos(1,1)
  print("Password correct!") -- Prints 'Password correct!' to the screen
  rs.setOutput(side,true) -- Output a redstone current to the side you specified
  print("press BACKSPACE to close!")
  while close == false do
  local p1 = os.pullEvent("key")
  if p1 == exitk then
   rs.setOutput(side,false) -- Stop outputting a redstone current
   close = true
   os.reboot()
 
   
  end
end
 
  elseif input == "debugultrasecurity" then -- checks if the user inputted the code to debug the program
break -- breaks the program

else -- Checks if the user didn't input the correct password
  print("Password incorrect!") -- Prints 'Password incorrect!' to the screen
  sleep(2) -- Waits 2 seconds
end
end
nono i press backspace and nothing happens. IT HANGSSSS
Grim Reaper #7
Posted 23 November 2012 - 09:00 AM

local side = "left" -- Change left to whatever side your door / redstone is on, E.G: left, right, front, back, bottom, top. Be sure to leave the "s around it, though
local password = "owncod1811" -- Change bacon to what you want your password to be. Be sure to leave the "s around it, though
local exitk = 14
local close = false
local opentime = 4 -- Change 5 to how long (in seconds) you want the redstone current to be on. Don't put "s around it, though
while true do
term.clear() -- Clears the screen
term.setCursorPos(1,1) -- Fixes the cursor position
write("Password: ") -- Prints 'Password: ' to the screen
local input = read("=") -- Makes the variable 'input' have the contents of what the user types in, the "=" part censors out the password
if input == password then -- Checks if the user inputted the correct password
  term.clear() -- Already explained up top
  term.setCursorPos(1,1)
  print("Password correct!") -- Prints 'Password correct!' to the screen
  rs.setOutput(side,true) -- Output a redstone current to the side you specified
  print("press BACKSPACE to close!")
  while close == false do
  local p1 = os.pullEvent("key")
  if p1 == exitk then
   rs.setOutput(side,false) -- Stop outputting a redstone current
   close = true
   os.reboot()

  
  end
end

  elseif input == "debugultrasecurity" then -- checks if the user inputted the code to debug the program
break -- breaks the program

else -- Checks if the user didn't input the correct password
  print("Password incorrect!") -- Prints 'Password incorrect!' to the screen
  sleep(2) -- Waits 2 seconds
end
end
nono i press backspace and nothing happens. IT HANGSSSS

This is because when you state:

local p1 = os.pullEvent("key")
p1 gets the name of the event that is passed, being "key".
Try rewriting it as this:

local _, p1 = os.pullEvent("key")
The above should let you capture the numerical value for the key pressed.
techlevel123 #8
Posted 24 November 2012 - 03:49 AM
Thanks ;)/>/>
is there a place to share code?
just wondering.
remiX #9
Posted 24 November 2012 - 05:03 AM
Pastebin