3 posts
Posted 02 April 2016 - 10:19 AM
I don't really know how to code Lua, but I've been trying to make a program that sets off an alarm when the Arc Furnace runs out of electrodes.
I had several variations, but this was the closest I got .
arc = peripheral.wrap("left")
while
arc.hasElectrodes(false) do
redstone.setOutput("top",true)
end
if arc.hasElectrodes(true) then
redstone.setOutput("top", false)
end
I could get it to run, but it output a redstone signal even if there were electrodes in the furnace. If some of could help me that would be awesome.
41 posts
Posted 02 April 2016 - 06:11 PM
You are on the right track. The error is the function hasElectrodes
returns a bool. (true / false) Try it like this :
arc = peripheral.wrap( "left" )
redstone.setOutput( "top", false )
while arc.hasElectrodes( ) do
sleep( 1 )
end
redstone.setOutput( "top", true )
Edited on 02 April 2016 - 05:04 PM
15 posts
Posted 02 April 2016 - 06:12 PM
I don't really know the api for arc furnaces so if you linked a page with the documentation i can help you better but if i had to take a guess the code should look like this.
arc = peripheral.wrap("left")
while true do --# will loop forever. Hold ctrl+ t to stop it
if arc.hasElectrodes() == false then
redstone.setOutput("top",true)
end
if arc.hasElectrodes()== true then
redstone.setOutput("top", false)
end
end
41 posts
Posted 02 April 2016 - 07:38 PM
I have tested it and the function hasElectrodes only returns true when it has all three electrodes. Any less and it will return false.
snip of sourcecode from IE
case 6://hasElectrodes
return new Object[]{te.electrodes[0] && te.electrodes[1] && te.electrodes[2]};
I think you need to use getElectrode.
Edited on 02 April 2016 - 06:58 PM
3 posts
Posted 02 April 2016 - 08:14 PM
You are on the right track. The error is the function hasElectrodes
returns a bool. (true / false) Try it like this :
arc = peripheral.wrap( "left" )
redstone.setOutput( "top", false )
while arc.hasElectrodes( ) do
sleep( 1 )
end
redstone.setOutput( "top", true )
A problem I found is that the alarm doesn't turn off when I put electrodes in
Edited on 02 April 2016 - 07:15 PM
41 posts
Posted 02 April 2016 - 08:44 PM
Something like this, you can modify, put it into a eternal loop, etc as you wish.
redstone.setOutput( "top", false )
furnace = peripheral.find( "IE:arcFurnace" )
repeat
sleep( 1 ) --# dont overload the system
nElectrodes = 3
for nIndex = 1, 3 do
if furnace.getElectrode( nIndex ).damage == nil then
nElectrodes = nElectrodes - 1
end
end
until nElectrodes == 0
redstone.setOutput( "top", true )
Edited on 03 April 2016 - 04:31 PM
41 posts
Posted 02 April 2016 - 09:28 PM
A problem I found is that the alarm doesn't turn off when I put electrodes in
Because the code i posted ends at that point. You can do a eternal loop as
Unknowntissue posted.
Edited on 02 April 2016 - 07:29 PM
3 posts
Posted 03 April 2016 - 12:16 AM
A problem I found is that the alarm doesn't turn off when I put electrodes in
Because the code i posted ends at that point. You can do a eternal loop as
Unknowntissue posted.
How would I implement that into your code?
41 posts
Posted 03 April 2016 - 11:39 AM
redstoneOutput = "top"
furnace = peripheral.find( "IE:arcFurnace" )
while true do
nElectrodes = 3
for nIndex = 1, 3 do
if furnace.getElectrode( nIndex ).damage == nil then
nElectrodes = nElectrodes - 1
end
end
if nElectrodes == 0 then redstone.setOutput( redstoneOutput, true )
else redstone.setOutput( redstoneOutput, false ) end
sleep( 1 )
end
Edited on 03 April 2016 - 04:32 PM