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

Witchery Auto Cauldron

Started by alphadude12, 19 February 2018 - 09:52 PM
alphadude12 #1
Posted 19 February 2018 - 10:52 PM
I am super new to programming and I know very little. On the server I play on I am trying to set up an auto witchery cauldron. I am trying to use another mod to gain automated immortality. I figured out how to automate everything else but because the cauldron requires items to be dropped in a certain order and at certain times it became very complicated to automate. I am using a turtle to drop items into the cauldron and a translator computer to tell the turtle what items the auto system requires. The system needs to make three recipes mutandis, mutandis extremis, and Drop of Luck. it doesn't give me an error but the program stops and gives me a random number (as far I can tell), or it does nothing. It is almost always on the turtle side. If anyone can help that would be much appreciated. I think it has something to do with the way I am trying to make it repeat.

here is my setup

https://imgur.com/a/lOE9o

here is my code

Translator
while rs.getInput("back") == true do
	if rs.getInput("right") == true then
		rs.setBundledOutput("top", 1)
		print("making mutandis")
		sleep(2)
		rs.setBundledOutput("top", 0)
	elseif rs.getInput("bottom") == true then
		rs.setBundledOutput("top", 2)
		print("making mutandis extremis")
		sleep(2)
		rs.setBundledOutput("top", 0)
	elseif rs.getInput("left") == true then
		rs.setBundledOutput("top", 3)
		print("making Drop of luck")
		sleep(2)
		rs.setBundledOutput("top", 0)
	end
end

Turtle
while true do
	event = os.pullEvent()
	if event == "redstone" then
		break
	end
end

if rs.getBundledInput("top") == 1 then
	turtle.select(1)
	turtle.dropDown(1)
	sleep(5)
	turtle.select(2)
	turtle.dropDown(1)
	sleep(5)
	turtle.select(3)
	turtle.dropDown(1)
	sleep(30)
	rs.setOutput("front", true)
	sleep(5)
	rs.setOutput("front", false)
elseif rs.getBundledInput("top") == 2 then
	turtle.select(5)
	turtle.dropDown(1)
	sleep(5)
	turtle.select(6)
	turtle.dropDown(1)
	sleep(30)
	rs.setOutput("front", true)
	sleep(5)
	rs.setOutput("front", false)
elseif rs.getBundledInput("top") == 3 then
	turtle.select(1)
	turtle.dropDown(1)
	sleep(5)
	turtle.select(5)
	turtle.dropDown(1)
	sleep(5)
	turtle.select(9)
	turtle.dropDown(1)
	sleep(5)
	turtle.select(10)
	turtle.dropDown(1)
	sleep(5)
	turtle.select(11)
	turtle.dropDown(1)
	sleep(30)
	rs.setOutput("front", true)
	sleep(5)
	rs.setOutput("front", false)
else
	sleep(20)
end
Edited on 20 February 2018 - 12:35 AM
Bomb Bloke #2
Posted 20 February 2018 - 01:41 AM
When you use a keyword that relies on a condition (such as "while" or "if"), it'll check to see whether the condition you provide is true. That means adding a "== true" yourself is redundant, because you're then asking the interpreter to check whether "X == true" == true.

That is to say, this sort of thing:

while rs.getInput("back") == true do

… is better written as:

while rs.getInput("back") do

I've indented the code in your post, which should better display the flow of execution. As you can see, most of the code your turtle is running isn't sitting inside your "while" loop - so the turtle will wait for a single redstone state change, then perform at most one action before ending its script. I suggest re-structuring it into something like this:

while true do
	repeat until os.pullEvent() == "redstone"

	if rs.getBundledInput("top") == 1 then
		-- etc
	elseif rs.getBundledInput("top") == 2 then
		-- etc
	elseif rs.getBundledInput("top") == 3 then
		-- etc
	else
		sleep(20)
	end
end
Lupus590 #3
Posted 20 February 2018 - 12:01 PM
while true do
    --# repeat until --# Edit: also not needed, as Bomb Bloke said
    os.pullEvent("redstone") --# An aditional change, by telling the OS what...
--# event you want to pull, it doesn't have to continue your program just for the...
--# unwanted event to be rejected. With this change, the OS can check what event you...
--# wanted, and not 'pass forward' the unwanted ones, thus you will only be given redstone...
--# events. This is better for the OS, and by 'OS' I actually mean the ComputerCraft virtual...
--# machine which runs every computer in your Minecraft world.

	if rs.getBundledInput("top") == 1 then
		-- etc
	elseif rs.getBundledInput("top") == 2 then
		-- etc
	elseif rs.getBundledInput("top") == 3 then
		-- etc
	else
		sleep(20)
	end
end
Edited on 21 February 2018 - 11:26 AM
Bomb Bloke #4
Posted 21 February 2018 - 05:42 AM
That works too, although it makes the "repeat" loop redundant.