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

RedNet Turtle control help

Started by thefossilman, 27 January 2015 - 11:29 PM
thefossilman #1
Posted 28 January 2015 - 12:29 AM
I am trying to automate Witchery circle magic rituals with a touchscreen monitor and a turtle. I want the turtle to start above the heart glyph of the circle and go forward 3 blocks to check what type of circle it is and send it to the monitor to display. so far i press the button and the turtle goes and checks the chalk (i know it works because i told it to print to the turtle before it sent it and it printed) but it doesnt display on the monitor. Plz help. Here is the code for the turtle
  • rednet.open("right")
  • local torf,block = turtle.inspectDown()
  • while true do
  • id,message = rednet.receive()
  • if id == 1 then
  • if message == ("curse of crazy") then
  • turtle.forward()
  • turtle.forward()
  • turtle.forward()
  • turtle.inspectDown()
  • if block.name == ("witchery:circleglyphinfernal") then
  • turtle.back()
  • turtle.back()
  • turtle.back()
  • else print("ERROR")
  • rednet.send(1,"ERROR! Invalid circle!")
  • end
  • end
  • end
  • end
I just realized the part that said torf is not used anywhere in the program, so you can ignore that.
And heres the one for the computer

  • os.loadAPI("button")
  • m = peripheral.wrap("right")
  • m.clear()
  • rednet.open("top")
  • function fillTable()
  • button.setTable("Curse of Crazy", crazycurse, 10,30,3,8)
  • button.screen()
  • end
  • function getClick()
  • event,side,x,y = os.pullEvent("monitor_touch")
  • button.checkxy(x,y)
  • end
  • function crazycurse()
  • button.toggleButton("Curse of Crazy")
  • rednet.send(20,"curse of crazy")
  • sleep(0.5)
  • button.toggleButton("Curse of Crazy")
  • if rednet.receive() == "ERROR! Invalid circle!" then
  • m.print("ERROR")
  • end
  • end
  • fillTable()
  • while true do
  • getClick()
  • end
Also please not that i am using direwolf20's button API so thats what os.loadAPI("button") is.
ps sorry the code parts look weird its my first post, not sure how to make it look right. it did before, until i pressed preview post. Then it got messed up.
Bomb Bloke #2
Posted 28 January 2015 - 02:23 AM
I suppose it might be re-done like so:

rednet.open("right")

while true do
	local id, message = rednet.receive()
	if id == 1 and message == "curse of crazy" then
		turtle.forward()
		turtle.forward()
		turtle.forward()
		
		local torf, block = turtle.inspectDown()
		if block.name == "witchery:circleglyphinfernal" then
			rednet.send(1,"Found some sort of infernal glyph thingy.")
		else
			print("ERROR")
			rednet.send(1,"ERROR! Invalid circle!")
		end
		
		turtle.back()
		turtle.back()
		turtle.back()
	end
end

os.loadAPI("button")
local m = peripheral.wrap("right")
m.clear()
rednet.open("top")

local function monPrint(text,x,y)
	local curX, curY = m.getCursorPos()
	x, y = x or curX, y or curY
	m.setCursorPos(x,y)
	m.write(text)
	m.setCursorPos(x,y+1)
end	

local function crazycurse()
	button.toggleButton("Curse of Crazy")
	sleep(0.5)
	button.toggleButton("Curse of Crazy")
	rednet.send(20,"curse of crazy")
	
	local id, message = rednet.receive()
	monPrint(message)  -- No such thing as "m.print"
end

button.setTable("Curse of Crazy", crazycurse, 10,30,3,8)
button.screen()

while true do
	event,side,x,y = os.pullEvent("monitor_touch")
	button.checkxy(x,y)
end

Use code tags to display your code correctly: [code]Code goes in here[/code]
Edited on 28 January 2015 - 01:29 AM
HPWebcamAble #3
Posted 28 January 2015 - 02:25 AM
Use code tags to display your code correctly

Also, copy pasting might keep the formatting, so paste into a plain text editor first to remove formatting.
Edited on 28 January 2015 - 01:25 AM