Off Topic > Games
Minecraft Megathread; yeah its update 1.12 big whoop what about it
Pages: << < (19483/20200) > >>
BlockoCrafter:
Can a Computercraft expert help me out here?
I'm trying to have my auto-sugarcane farm loop itself, but simulataneously look for a rednet message for when to stop. Whenever I try to incorporate the receiving part of the code, the operation pauses. By the way, I'm using 1.6 so I can't have a separate program running the reciever.
Kingdaro:
Post your current code? Theoretically, you could just have something like this:
local farming = true
while true do
if farming then
farmSugarCanes()
end
if receivedStopSignal() then
farming = not farming
end
end
Where it's essentially a sort of toggle, and receiving the rednet signal toggles the farming (the farming = not farming line).
seargent227:
I'm not nearly close to an expert but I like messing around with computer craft. I'm pretty sure the program pauses until the message is received. You might be able to fix this by adding the receiving line outside of the loop, so after it. (Not sure if it works but you can try it)
Kingdaro:
If the receiving line is added outside of the loop, the loop will never check if it's receiving the signal. What you could do is implement a timeout, where it'll either receive the signal, or wait a couple of seconds. http://computercraft.info/wiki/Timer_(event)
Another option is running a parallel.waitForAny, where the first part always runs, and the second stops when the signal is received, e.g.
function farm()
-- sugar cane farming stuff
end
function getSignal()
while true do
-- event pulling stuff
if receivedStopSignal() then
return -- this should stop the waitForAny if we received the signal
end
end
end
parallel.waitForAny(farm, getSignal)
BlockoCrafter:
--- Quote from: Kingdaro on March 30, 2014, 04:09:29 PM ---Post your current code? Theoretically, you could just have something like this:
local farming = true
while true do
if farming then
farmSugarCanes()
end
if receivedStopSignal() then
farming = not farming
end
end
Where it's essentially a sort of toggle, and receiving the rednet signal toggles the farming (the farming = not farming line).
--- End quote ---
You're right. Posting the code would have been a good idea. Thankfully, I can adapt your concept into what I've got. Thanks for the help.
EDIT: It's working. I've got a farm where every turtle stands in front of a stalk. It's not very resource friendly, but it doesn't require reprogramming when making changes to the farm.
Here's the code:
1. Put this in the main computer with a wireless modem on the right: http://pastebin.com/gejw6jKX - startup
2. Put these in wireless farming turtles and put a chest below them: http://pastebin.com/Ct66h12A -startup http://pastebin.com/LMibAq4F - auto
(Turtles contain code if you wish to put a monitor on top of it.)
If you guys got cleanup suggestions, go for it.