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

Need Help with Turtle

Started by SpyEnnC, 20 October 2014 - 10:08 PM
SpyEnnC #1
Posted 21 October 2014 - 12:08 AM
I am trying to create a program that the turtle select a slot and print the word so here the code.

rednet.open("right")
function mob()
local mob = {skeleton = 1, cow = 2, pig = 3}
turtle.select(mob)
end
function display()
local id, msg = rednet.receive()
if msg == "Hi" then
print("Hello")
  elseif msg ~= "Hi" then
   print(msg)
  else
   mob()
  end
while true do
display()
end
Also this is just a test code but still very important to me.
Edited on 20 October 2014 - 11:12 PM
Bomb Bloke #2
Posted 21 October 2014 - 01:30 AM
local mob = {skeleton = 1, cow = 2, pig = 3}

rednet.open("right")

while true do
	local id, msg = rednet.receive()
	
	if msg == "Hi" then
		print("Hello")
	elseif mob[msg] then  -- So long as the message points to a valid entry in the table...
		print("Selecting "..msg.."...")
		turtle.select(mob[msg])
	else
		print("Invalid message: "..msg)
	end
end
SpyEnnC #3
Posted 21 October 2014 - 02:23 AM
Thanks for the help. I would like it in a function but it work for me still. Once again thank for your help.
Dragon53535 #4
Posted 21 October 2014 - 02:43 AM

local mob = {skeleton = 1, cow = 2, pig = 3}
rednet.open("right")
local function display()
		local id, msg = rednet.receive()
	  
		if msg == "Hi" then
				print("Hello")
		elseif mob[msg] then  -- So long as the message points to a valid entry in the table...
				print("Selecting "..msg.."...")
				turtle.select(mob[msg])
		else
				print("Invalid message: "..msg)
		end
end
while true do
  display()
end

Just so you know, it's the exact thing he put, except in a function.
Edited on 21 October 2014 - 12:43 AM