Posted 08 October 2012 - 08:00 PM
So im working in a wireless crafting system via rednet. The basics are that i send a message from my home computer to a main server in my basement, and this computer then sends it to the crafty turtle. All that part is solved out and it sends all the messages.
Please there are 3 main files, plz take a look at them. check the comments to know the specific part of the problem. :D/>/>
Thanks in advance for your help and support.
This is my crafty Turtle startup file.
This is my Main Server Startup File
This is my Message program from home, just to test the recipe name…
Please there are 3 main files, plz take a look at them. check the comments to know the specific part of the problem. :D/>/>
Thanks in advance for your help and support.
This is my crafty Turtle startup file.
function reFuel()
if turtle.getFuelLevel()<50 then
print("Refueling...")
turtle.turnRight()
turtle.turnRight()
turtle.select(1)
turtle.suck()
turtle.drop(turtle.getItemCount()-2)
turtle.refuel(2)
turtle.turnLeft()
turtle.turnLeft()
turtle.select(1)
end
end
function moveToChest(;)/>/>
for i=1,b do
turtle.forward()
end
turtle.turnRight()
end
function goBackHome(:D/>/>
turtle.turnLeft()
for j=1,b do
turtle.back()
end
turtle.turnRight()
turtle.drop()
turtle.turnLeft()
end
function readName()
rednet.open("right")
while true do
turtle.select(1)
shell.run("clear")
print("Waiting for Server Instructions")
id,message = rednet.receive() -- REDNET MESSAGE from my server
print(message)
if message == recipe[name] then
rednet.send(id,"Getting Required Items")
craftRecipe(recipe[name])
rednet.send(id,"Crafting Complete")
else
rednet.send(id,"I Don't Know That Recipe")
sleep(2)
end
end
end
-- Crafting, dont worry about this, it's totally working
function craftRecipe(recipe)
moveToChest(recipe.chest)
turtle.select(1)
for k,v in pairs(recipe.map) do
turtle.select(k)
if v then
turtle.suck()
turtle.drop(turtle.getItemCount(k)-1)
end
end
turtle.craft()
goBackHome(recipe.chest)
end
-- End of Basic Functions
-- My crafting system is based on tables
recipe={
["stick"] = {
count=2,
chest=3,
map={
[1]=false, [2]=false, [3]=false,
[5]=false, [6]=true, [7]=false,
[9]=false, [10]=true, [11]=false
}
},
["furnace"] = {
count=8,
chest=4,
map={
[1]=true, [2]=true, [3]=true,
[5]=true, [6]=false, [7]=true,
[9]=true, [10]=true, [11]=true
}
}
}
-- End of Recipes List
reFuel()
readName()
This is my Main Server Startup File
rednet.open("left")
function centerText(text) -- Center text stuff, dont look at it
local x,y = term.getSize()
local x2,y2 = term.getCursorPos()
term.setCursorPos(math.ceil((x/2)-(text:len()/2)),y2)
write(text)
end
term.clear()
centerText("Master Server")
term.setCursorPos(1,3)
centerText("Waiting for Messages")
term.setCursorPos(1,5)
--Wait for rednet Messages...
while true do -- It sends all the messages back and forth from home, server, turtle and viceversa.
id,message=rednet.receive()
print("From #"..id..": "..message)
if id==9 then
rednet.send(20,message)
elseif id==20 then
rednet.send(9,message)
end
end
This is my Message program from home, just to test the recipe name…
rednet.send(22,"furnace")
id,message=rednet.receive()
print("From #"..id..": "..message)