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

Turbine of Big reactors

Started by Woody709, 27 February 2016 - 05:34 PM
Woody709 #1
Posted 27 February 2016 - 06:34 PM
Hi everyone.
i am witing a code that automate the turbine of big reactors.
it works as followed: look if the turbine is atached to the compure at the back side.
then check if there is a redtone signal from the bottom and if its true check if the turbine coils are active.
if active shut the coils down if deactive keep them deactiveted.
here is a pastebin link : http://pastebin.com/w8MA6Jst
and here are some screenshots:
http://imgur.com/a/yJJSB

but i can't get it to work properly.
can someone help me
KingofGamesYami #2
Posted 27 February 2016 - 08:44 PM
Here is your code again, properly indented to show the problem


local Turbine
turbine= peripheral.wrap("back")
turbine.getInductorEngaged()
if turbine.getInductorEngaged(true) then
end
if turbine.getInductorEngaged(false) then
end
if redstone.getAnalogInput(true) then
end
if redstone.getAnalogInput(false) then
turbine.setInductorEngaged(true)
end
end --# << Extra end

Have you considered using else or elseif? Also, I'm fairly certain none of those take a boolean argument (aside from the setInductorEngaged). If you wanted to compare the output, you should use == (or, in the case that it does return a boolean value, you don't need to compare it). I'm also fairly certain that anything returned by redstone.getAnalogInput will be a number, which evaluates to true in any if/then statement.
Edited on 27 February 2016 - 07:44 PM
Woody709 #3
Posted 27 February 2016 - 09:20 PM
could you give me an exsample of what you mean with using else or elseif in my code
KingofGamesYami #4
Posted 28 February 2016 - 01:04 AM
An else statement executes if the parameters for if were false, eg:


if true then
  --#this will be executed
  print( "True!" )
else
  --#this will not be executed
  print( "False!" )
end

if false then
  --#this will not be executed
  print( "True!" )
else
  --#this will be executed
  print( "False!" )
end

An elseif is simply an extension of else, allowing more than one option:


local i = 1
if i == 1 then
  --#i is equal to 1, so this is being executed
elseif i == 2 then
  --#i is not equal to 1, and is equal to 2, so this is being executed
elseif i == 3 then
  --#i is not equal to 1 or 2, and is equal to 3, so this is being executed
else
  --#i is not equal to 1, 2, or 3, so this is being executed
end

In the following example, I have "fixed" several obvious issues with your code. Please note that it has not been tested and may not work, depending on your setup. As you did not provide the correct arguments to redstone.getAnalogInput (the correct one is a side name), I have assumed the input is on the right. As you did not provide any context as to what you wanted the code to do, I have left the same empty code blocks in the example. As you did not specify which signal strength you wished to compare against, I have defaulted to greater than or equal to 1 (0 is no redstone input, 16 is full redstone input). If this was the result you wished to get, I would advise you to use the much simpler redstone.getInput( "right" ), which simply returns true if any input is received on the right side, and false if no input is detected.


local turbine
turbine = peripheral.wrap( "back" )
if turbine.getInductorEngaged() then
  --#the reactor is engaged, do whatever
else
  --#the reactor is not engaged, do whatever
end
if redstone.getAnalogInput( "right" ) >= 1 then
  --#a redstone signal greater than or equal to 1 is being sent from the right side
else
  --#no redstone signal of the required power has been detected
  turbine.setInductorEngaged(true)
end