Is there a way to have it automatically recharge, or do I have to do it manually? Also, Is it possible to have the turtle run it's programs when it receives a Redstone Signal?
Yes to both things, although it will require editing the original program just a bit.
By the way, everything I say is based on the screenshot you posted earlier so some directions and other stuff might be wrong, but that shouldn't be too hard to tweak. To be honest, this is starting to get to be quite a big program. I am willing to help you but before I write any actual code for this application I will tell you about a couple of core concepts and then you can apply those.
First of all, are conditionals. This checks if a certain condition is satisfied and executes code based on that.
This is important for making this program activate when it receives a redstone signal. Especially when combined with events (another concept which I will talk about later)
to open a conditional you need this keyword> if
then you write the variable that you are checking. You can call another variable or just write something into it
then you write what you are checking it against. Use the following checks, == if you want to check if x does equal y, > if x is greater than y, < if x is less than y, ~= if x does not equal y, followed by the check variable
finish the condition statement by writing >then
then type the code that you want to execute if the condition is met followed by > end
I will give an example script that will demonstrate conditionals
local digit = 5
if digit > 2 then
print("digit is greater than 2")
elseif digit == 2 then
print("digit does equal 2")
else
print("digit is not greater than 2")
end
events are things that happen to the computer/turtle that can be detected. If you want the computer/turtle can wait to do its job until a defined event has happened using this command
local event = os.pullEvent(type of event)
type of event can be a string for example "redstone". If you type os.pullEvent("redstone") into a code, everything after it will only happen once the event has been triggered
you can follow this with a condition to check if the redstone input is true and then execute the main code if it is true
functions
functions are pieces of code that exist that can be called by the program. They make writing programs cleaner and easier, and if you need to execute the same piece of code several times in a program, put that code inside a function.
To make a function, write function followed by the name of the function and then a pair of parentheses. Then on the next line put in your code and close it by writing end. Here is an example
function message()
print("hello world")
end
when this function is called it will execute the code within, i.e hello world will appear on the screen.
You can put a variable inside the function to make the function do subtly different things each time it is called.
function message(printThis)
print(printThis)
end
message("Hello world")
message("I am doing stuff")
local anotherMessage = "You can pass variables too. This string is a variable"
message(anotherMessage)
---
will result in:
Hello world
I am doing stuff
You can pass variables too. This string is a variable
you can write a refueling function that will detect how much fuel the turtle has and if it is less than what it needs it will get fuel and refuel. You can put a chest full of fuel underneath the turtle at the turtle's starting point and the turtle can pull from that chest and use the fuel to refuel. So long as you keep the chest supplied it should be ok. Or you could export coal with your logistics system directly to the turtle, but I would recommend the chest method (only because that is what I do, turtles are very versatile and when you get to grips with it the coding you can get them to do tonnes of stuff in the way that you want/need).
finally, loops
I used a for loop in the program I wrote earlier
another type of loop is the while loop which checks a condition and runs if the condition is met, forever or until the condition is no longer met.
To set a program to run in perpetuity encase it in a while loop like this
while true do
code() -- whatever you want to code
end
and that will run forever. It is advisable to put a sleep() command at the end of the while loop (before writing end) because if the block is constantly doing stuff it might become a miniature lag machine. A setup like this is usually preferable for me at least for the programs I have written. An alternative is waiting for events.
while true do
code()
sleep(5)
end
In this case code could be waiting for a redstone event, checking to see if redstone is true and then running the code I wrote earlier with the refuel function put in at the beginning. If you try to make sure that the turtle has 100 fuel at all times I think that will serve you well. I may have missed something. I wrote this post, quite piecemeal so sorry if its fragmented but I am busy. If I missed anything or if it is still unclear here are some good links
http://computercraft.info/wiki/Category:APIs -- This link is important. There are tons of useful commands containing most of the stuff you will be wanting to do with computercraft (probably). Two important ones are redstone api and turtle api
http://computercraft.info/wiki/Turtle_(API) -- Contains movement command, inventory management commands and also refueling commands.
http://computercraft.info/wiki/Redstone_(API)
http://computercraft.info/wiki/Tutorials -- The introduction to coding bit is very useful and may well contain the answer to any question you have left.
Whoa this post is long, I sure hope it helps