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
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Outputting redstone on redstone input
Started by rufjame, 07 December 2013 - 04:35 AMPosted 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?
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.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
so knowing the above you can just do
there is no point comparing a boolean against a boolean ;)/>
- 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 ;)/>
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.
Posted 07 December 2013 - 09:32 PM
that may be needed for OPs use case.Also the first sleep() isn't needed. It tells your program to wait 30 seconds before it does anything.
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
Posted 08 December 2013 - 04:44 PM
in that case you're not comparing a boolean against a boolean are you‽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
Posted 08 December 2013 - 05:20 PM
Actually, if you have crappy code. No offense there for anyone else who is doing this:in that case you're not comparing a boolean against a boolean are you‽
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