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

My code is messed up somewhere

Started by bradenheron, 04 May 2013 - 01:30 AM
bradenheron #1
Posted 04 May 2013 - 03:30 AM
while true do
[indent=1]local monitor = peripheral.wrap("left")[/indent]
[indent=1]local side = "bottom"[/indent]
[indent=1]monitor.clear()[/indent]
[indent=1]redstone.testBundledInput(side, colors.blue)[/indent]
[indent=1]monitor.setCursorPos(1,1)[/indent]
[indent=1]monitor.write("Farm Engine Status: ")[/indent]
[indent=2]if true then[/indent]
[indent=3]monitor.setCursorPos(21,1)[/indent]
[indent=3]monitor.write "Active"[/indent]
[indent=2]else[/indent]
[indent=3]monitor.setCursorPos(21,1)[/indent]
[indent=3]monitor.write "Error!"[/indent]
[indent=2]end[/indent]
[indent=1]sleep(5)[/indent]
end

What I am wanting this to do is to pick up if there is a signal in the blue cable and if there is to print active otherwise print error. The problem that I am having is that my monitor is permanently saying "Farm Engine Status: Active". How can I fix this? I am wanting to make it so that eventually I will have many different colors of wire feeding input into the computer. I know for sure that the wire is not live and yet it is still saying "Active"

Thanks,

Braden
Mads #2
Posted 04 May 2013 - 03:51 AM
You test if true is true, which it always is. Lua doesn't push values and compare them later, like CMP in Intel x86 Assembly, so you will have to replace this:
if true then
with this:
if redstone.testBundledInput(side, colors.blue) then

And if you'd have more options, you'd do this:

if redstone.testBundledInput(side, colors.blue) then
	-- code if blue
elseif redstone.testBundledInput(side, colors.red) then
	-- code if red
else
        -- code otherwise
end
bradenheron #3
Posted 05 May 2013 - 02:14 PM
OK thank you very much Mads, I will try that out here sortly