Jump to content




[Solved] Variable Difficulties

computer lua peripheral

  • You cannot reply to this topic
3 replies to this topic

#1 Alzarath

  • New Members
  • 2 posts

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.

#2 ChunLing

  • Members
  • 2,027 posts

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 "--"

#3 Alzarath

  • New Members
  • 2 posts

Posted 21 December 2012 - 05:22 PM

View PostChunLing, on 21 December 2012 - 04:59 PM, said:

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.

#4 ChunLing

  • Members
  • 2,027 posts

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users