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

Help Please!

Started by jason03272002, 09 January 2015 - 05:23 PM
jason03272002 #1
Posted 09 January 2015 - 06:23 PM
Each time I run my code, I get the error:

cycle:7: Expected string, boolean
Here's the code:

local now
  if now=1 then
  redstone.setOutput(left, true)
  redstone.setOutput(right, false
now = 2
else
  redstone.setOutput(right, true)
  redstone.setOutput(left, false)
now = 1
end
I can't find the problem, so please help!
Bubba #2
Posted 09 January 2015 - 06:28 PM
redstone.setOutput(right, true) should be redstone.setOutput("right", true)
Notice the quotes. It should be the same for rs.setOutput(left) -> rs.setOutput("left")

The reason for this is that redstone.setOutput takes a string indicating the side and a boolean to indicate on or off as arguments.
Edited on 09 January 2015 - 05:28 PM
jason03272002 #3
Posted 09 January 2015 - 06:32 PM
Oh yeah, strings have to be in quotes… never crossed my mind while I was debugging xD Thank you!
safetyscissors #4
Posted 10 January 2015 - 02:26 AM
Just a suggestion. If your variable 'now' is simply to toggle left and right sides, you can check it as the rs.setOutput boolean.
local now=1
redstone.setOutput('left', (now==1))
redstone.setOutput('right', (now~=1))
now=(now==1) and 2 or 1
Otherwise, might want to check that line2 became 'if now==1 then'
Bubba #5
Posted 10 January 2015 - 02:50 AM
Just a suggestion. If your variable 'now' is simply to toggle left and right sides, you can check it as the rs.setOutput boolean.
local now=1
redstone.setOutput('left', (now==1))
redstone.setOutput('right', (now~=1))
now=(now==1) and 2 or 1
Otherwise, might want to check that line2 became 'if now==1 then'

There's a far easier way to do this…

rs.setOutput("left", not rs.getOutput("left"))
Edited on 10 January 2015 - 08:12 PM
Dragon53535 #6
Posted 10 January 2015 - 03:15 AM
There's a far easier way to do this…

rs.setOutput("left", not rs.getInput("left"))
Technically you should probably do

rs.setOutput("left", not rs.getOutput("left"))
Since a repeater doesn't give an input, you could potentially be sending it to a repeater, and not getting an input ever.
Bubba #7
Posted 10 January 2015 - 09:12 PM
There's a far easier way to do this…

rs.setOutput("left", not rs.getInput("left"))
Technically you should probably do

rs.setOutput("left", not rs.getOutput("left"))
Since a repeater doesn't give an input, you could potentially be sending it to a repeater, and not getting an input ever.

Yep, that's true. Slight mistake on my part. I've edited mine to reflect this. Thanks for noticing it!