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

[CraftOS 1.2][Lua][Error] unexpected symbol? Trying to create a control script

Started by dtdsora, 17 March 2012 - 05:26 AM
dtdsora #1
Posted 17 March 2012 - 06:26 AM
I've been trying to create a control script to work with BuildCraft, IC2, and RedPower, this is what i had, but when i try to use it i get
"[string "disk/test"]:2: unexpected symbol"
I can guess the ":2:" is how many errors are left
oh, and i am using the version in Tekkit
function Maintain()
write("welcome") then
if r1 = 1 then
write("Ore Dust Extraction system is: ON. Turn it off? (Y/N)") then
t = io.read
if t = "Y" then
redstone.setBundledOutput("back", colors.magenta)
else
pass()
end
else
write("Ore Dust Extraction system if: OFF. Turn it on? (Y/N)") then
t = io.read
if t = "Y" then
redstone.setBundledOutput("back", colors.magenta)
set r1 = 1
end
end
Luanub #2
Posted 17 March 2012 - 07:04 AM
You dont need to put then after write.

So this…

function Maintain()
write("welcome")
if r1 = 1 then
write("Ore Dust Extraction system is: ON. Turn it off? (Y/N)")
t = io.read
if t = "Y" then
redstone.setBundledOutput("back", colors.magenta)
else
pass()
end
else
write("Ore Dust Extraction system if: OFF. Turn it on? (Y/N)")
t = io.read
if t = "Y" then
redstone.setBundledOutput("back", colors.magenta)
set r1 = 1
end
end

Keep in mind write does not end the line. From looking at your code your writes might all print on 1 line. Try using print instead of write if this happens or add print () where you want your line breaks.

I also noticed you didn't end some of your if statement. You either need to add some ends or change some of the if's to elseif.

so

if r1 = 1 then
write("Ore Dust Extraction system is: ON. Turn it off? (Y/N)")
t = io.read
if t = "Y" then
redstone.setBundledOutput("back", colors.magenta)
else
pass()
end

change to something like…

if r1 = 1 then
write("Ore Dust Extraction system is: ON. Turn it off? (Y/N)")
end  -- added this
t = io.read
if t = "Y" then
redstone.setBundledOutput("back", colors.magenta)
else
pass()
end
Edited on 17 March 2012 - 06:39 AM
dtdsora #3
Posted 17 March 2012 - 04:13 PM
You dont need to put then after write.

So this…
*snip*

Keep in mind write does not end the line. From looking at your code your writes might all print on 1 line. Try using print instead of write if this happens or add print () where you want your line breaks.

I also noticed you didn't end some of your if statement. You either need to add some ends or change some of the if's to elseif.

so
*snip*
change to something like…
*snip*

Im assuming your say to change it to this
function Maintain()
write("welcome")
end
if r1 = 1 then
write("Ore Dust Extraction System is: ON. Turn off? (Y/N)")
end
t = io.read
if t = "Y" then
redstone.setBundledOutput("back", colors.magenta)
set r1 = 0
else
pass()
end
else
write("Ore Dust Extraction System is: OFF. Turn On? (Y/N)")
end
t = io.read
if t = "Y" then
redstone.setBundledOutput("back", colors.magetna)
set r1 = 1
end
end
but this time I get
:4: 'then' expected
in other words, yes, it need the 'then's beside the writes. im assuming
MysticT #4
Posted 17 March 2012 - 08:00 PM
Fixed code:

function Maintain()
  write("welcome")
  if r1 == 1 then -- added =
    write("Ore Dust Extraction System is: ON. Turn off? (Y/N)")
    t = io.read() -- added ()
    if t == "Y" then -- added =
      redstone.setBundledOutput("back", colors.magenta)
      r1 = 0 -- removed set
    else
      pass()
    end
  else
    write("Ore Dust Extraction System is: OFF. Turn On? (Y/N)")
    t = io.read() -- added ()
    if t == "Y" then -- added =
      redstone.setBundledOutput("back", colors.magetna)
      r1 = 1 -- removed set
    end
  end
end
In lua you need to use == to compare values. Also, if you want to call a function with no parameters you need to put () after it. And there's no keyword set, tou just assign the values to the variables with "var = value".