I am in the proccess of coding a mining program using turtle. At the moment I have finished the mining aspect of the program. Further the turtles that do the mining are controlled by a main computer that (using direwolf20 's button API) displays buttons that can be used to start the mining process. What I have happen is that the user selects a distance they want to mine using 4 different presets. They then select the turtle that is to carry out the mining. What happens is that when the turtle is selected the button turns green indicating that it is mining. I have it set to send the mining instructions wirelessly.
One thing that I have not been able to do is that when the turtle is done mining it should send a signal back to the main computer to toggle the button back to a red state. This would indicate that the turtle has finnished its mining. I have looked into my code and have found out that the reason why it doesn't get the signal is that the os.pullEvent() function waits for an event before moving on to the next line of code. I need to make this pullEvent temporary. Maybe happen for a second then for another second it will wait for an incoming signal from the turtle. I have the following code:
while true do
getClick()
id, Report = rednet.receive(1)
if Report == "done" then
if id == 5 then
button.toggleButton("Miner1")
elseif id == 6 then
button.toggleButton("Miner2")
elseif id == 7 then
button.toggleButton("Miner3")
elseif id == 8 then
button.toggleButton("Miner4")
end
end
end
For anyone familiar with direwolfs button API the getClick function will be familiar however anyone that isn't what is basically does is wait for a monitor touch. The code above runs the getClick (which is where the problem lies with the os.pullEvent()) and then is should receive a message from the turtle with a string reading "done" it then checks which turtle it came from and toggles the appropriate button back to red. I have worked around this by having another computer that has a display that tells me if the turtle is done mining. getClick code below:
function getClick()
event,side,x,y = os.pullEvent("monitor_touch")
button.checkxy(x,y)
end
I was wondering if there is a way in which I can edit the getClick function or the API itself so as the loop from the main code will continue to run. I did find a post ( http://www.computerc...t-with-timeout/ ) that explained how to do it but the coder put the main code into the button API code and ran the program from that rather than use it as an API. I, being new to lua programming and computercraft, don't understand how to incorporate the code of that post into my main code using an API.
Another thing that i would love to do is have it so that buttons on the screen would be used to set the mining value. ie there would be a "+" and "-" button that would be used to set the value. I got this to partly work in tests however I did not know how to display the value on the screen. I got it to display the value however pressing the add and subtract buttons would not refresh the screen and so the value displayed would not update. But I have worked around that by having preset mining values that the miners could run.
Any help would be much appreciated.
Thanks
Robert
My entire code http://pastebin.com/nctbSbcj