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

[Solved] Variable Difficulties

Started by Alzarath, 21 December 2012 - 03:22 PM
Alzarath #1
Posted 21 December 2012 - 04:22 PM
Solved

I'm trying to get some local boolean variables working., but it's giving me an error,

Here's the code:

term.clear()
term.setCursorPos(1,1)
print("Scanning peripherals...")
if peripheral.isPresent("left") then
if peripheral.getType("left") == "monitor" then
  local monitorcheck = true
  monitor = peripheral.wrap("left")
elseif peripheral.getType("left") == "modem" then
  local modemcheck = true
  modem = peripheral.wrap("left")
end
end
if peripheral.isPresent("top") then
if peripheral.getType("top") -- "monitor" then
  local monitorcheck = true
  monitor = peripheral.wrap("top")
elseif peripheral.getType("top") == "modem" then
  local modemcheck = true
  modem = peripheral.wrap("top")
end
end
if monitorcheck == true then
print("Attaching monitor...")
sleep(0.4)
end
if modemcheck == true then
print("Attaching modem...")
sleep(0.4)
end
print("Setting up login process...")
sleep(0.4)
term.clear()
term.setCursorPos(1,1)
shell.run("disk/password")
shell.run("disk/login")

When I start up the computer (It's a startup program), I get the following:

CraftOS 1.4
bios:206: [string "startup"]:15: 'then' expected
>

I'm very new to programming, and through some Google searching I didn't seem to find anything (Maybe I just didn't look hard enough). Adding 'then' to the end of the mentioned line still gives the same error. Trying to use a global variable instead doesn't affect it either. I'm sure it's a very amateur mistake.
ChunLing #2
Posted 21 December 2012 - 04:59 PM
You commented out you then, on the line immediately prior. I guess you wanted:

if peripheral.getType("top") == "monitor" then
But you replaced the "==" with "–"
Alzarath #3
Posted 21 December 2012 - 05:22 PM
You commented out you then, on the line immediately prior. I guess you wanted:

if peripheral.getType("top") == "monitor" then
But you replaced the "==" with "–"

Oh wow, I feel like an idiot now. Thanks for pointing that out.
ChunLing #4
Posted 21 December 2012 - 06:44 PM
For longer programs you should use some kind of editor that gives you highlighting for Lua, most people probably use Notepad++. That makes spotting these kinds of things a lot easier.