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

Outputting redstone on redstone input

Started by rufjame, 07 December 2013 - 04:35 AM
rufjame #1
Posted 07 December 2013 - 05:35 AM
So what i'm trying to do is have the computer detect an input signal on one side and then output it again on the otherside for 30 seconds before restarting the program. However I continue to get either a "then" expected on line Exactly how bad is my current code and what can I do to make it work?


if rs.getInput("right") = true
  then
	sleep(30)
	redstone.setOutput("rear", true)
	sleep(30)
	redstone.setOutput("rear", false)
  os.reboot
  else
	sleep(30)
	os.reboot
Engineer #2
Posted 07 December 2013 - 08:57 PM
You compare with double = signs:

if something == true then

else

end
You are also missing an end to close the statement.
theoriginalbit #3
Posted 07 December 2013 - 09:18 PM
however, since rs.getInput returns a boolean you do not even need to perform the comparison, your conditional essentially is this
  • if true == true then is true equal to true? yes. you may as well just use the initial true.
  • if false == true then well is false equal to true? no. again you may as well just use the initial false.

so knowing the above you can just do

if rs.getInput("right") then
 --# statements
else
 --# statements
end

there is no point comparing a boolean against a boolean ;)/>
OReezy #4
Posted 07 December 2013 - 09:23 PM
Also the first sleep() isn't needed. It tells your program to wait 30 seconds before it does anything.
theoriginalbit #5
Posted 07 December 2013 - 09:32 PM
Also the first sleep() isn't needed. It tells your program to wait 30 seconds before it does anything.
that may be needed for OPs use case.
Engineer #6
Posted 08 December 2013 - 07:49 AM
there is no point comparing a boolean against a boolean ;)/>

Sometimes you need to, when you are using multiple value types on one variable. Then you may need to check for a boolean, but only then
theoriginalbit #7
Posted 08 December 2013 - 04:44 PM
Sometimes you need to, when you are using multiple value types on one variable. Then you may need to check for a boolean, but only then
in that case you're not comparing a boolean against a boolean are you‽
Engineer #8
Posted 08 December 2013 - 05:20 PM
in that case you're not comparing a boolean against a boolean are you‽
Actually, if you have crappy code. No offense there for anyone else who is doing this:

local function aFunction( b )
     if b then
        return (b == "crap" and "crap" or false)
     end
     return nil
end

local val = aFunction()
if val == "crap" then
    print("b == \"crap\"!")
elseif val == false then
    print("b exists but returned false :(/>")
elseif not val then
    print("b didnt exist :(/>")
end

Its odd to explain it, but this should make it more clear what I meant