Posted 07 June 2013 - 03:10 AM
Hi all, new to these forums, thought I'd drop in and check it out :)/>
I've been working on a completely automated fireworks factory using turtles and computers, and it's working great. However now comes the time where I try and optimize the system for speed. One issue I'm having is that one of my crafty turtles keeps timing out without yeilding, however putting a delay in the code slows it down a fair by the looks. Is there a way I can have the turtle yeild only when it's not trying to do something, instead of just a fixed delay in my loop? Or for that matter, optimize how the turtle distributes items between slots?
Basically what it does, is checks dur, which is the duration of the firework, then splits the item in the 2nd slot (gunpowder) between slots 3 and 5. This works fine, however it runs quite slowly, only moving once a second or so. It seems if the loop isn't really doing anything else, it should be able to run a bit faster. It's the bottleneck in my system.
So far I've managed to have it craft 32 fireworks with 6 dyes and 2 effects and a duration of 3 in about 1:30, but if I can speed up the moving items between slots, it'll be a lot faster. I plan on releasing this code once I've worked out the bugs, it took me a lot of time how to figure out how to craft fireworks automatically, allowing you to choose the ingredients :)/>/>
Sorry if the code is a bit messy, I have a bad habit of just throwing stuff together, then fixing it up once it works :)/>/>
Look forward to reading through the forums more.
I've been working on a completely automated fireworks factory using turtles and computers, and it's working great. However now comes the time where I try and optimize the system for speed. One issue I'm having is that one of my crafty turtles keeps timing out without yeilding, however putting a delay in the code slows it down a fair by the looks. Is there a way I can have the turtle yeild only when it's not trying to do something, instead of just a fixed delay in my loop? Or for that matter, optimize how the turtle distributes items between slots?
Basically what it does, is checks dur, which is the duration of the firework, then splits the item in the 2nd slot (gunpowder) between slots 3 and 5. This works fine, however it runs quite slowly, only moving once a second or so. It seems if the loop isn't really doing anything else, it should be able to run a bit faster. It's the bottleneck in my system.
So far I've managed to have it craft 32 fireworks with 6 dyes and 2 effects and a duration of 3 in about 1:30, but if I can speed up the moving items between slots, it'll be a lot faster. I plan on releasing this code once I've worked out the bugs, it took me a lot of time how to figure out how to craft fireworks automatically, allowing you to choose the ingredients :)/>/>
Sorry if the code is a bit messy, I have a bad habit of just throwing stuff together, then fixing it up once it works :)/>/>
modem = peripheral.wrap("right")
modem.open(1)
modem.open(2)
gotAmt = false
craftedAmt = 0
rxamt = false
rxdur = false
splitItems = false
while (true) do
if gotAmt == false then
local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
if senderChannel == 1 then
amt = message
rxamt = true
print(amt)
end
if senderChannel == 2 then
dur = message
rxdur = true
print(dur)
end
if rxamt == true and rxdur == true then
gotAmt = true
end
end
if dur == 2 then
if turtle.getItemCount(2) > amt then
turtle.select(2)
turtle.transferTo(3,1)
end
end
if dur == 3 then
if turtle.getItemCount(2) > amt then
turtle.select(2)
turtle.transferTo(3,1)
end
if turtle.getItemCount(3) > amt then
turtle.select(3)
turtle.transferTo(5,1)
end
end
if turtle.getItemCount(11) == amt+1 then
if dur == 1 and turtle.getItemCount(2) == amt or dur == 2 and turtle.getItemCount(3) == amt or dur == 3 and turtle.getItemCount(5) == amt then
turtle.select(16)
turtle.craft(amt)
turtle.drop()
gotAmt = false
rxdur = false
rxamt = false
print("Crafted all!")
end
end
sleep(0.01)
end
Look forward to reading through the forums more.