This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
calmilamsy's profile picture

Advanced manual turtle

Started by calmilamsy, 06 April 2013 - 08:11 AM
calmilamsy #1
Posted 06 April 2013 - 10:11 AM
Hello ive been working on a turtle program that i can use easily without long commands such as "go forward" so i wipped up this:-

the code isnt that clean :unsure:/> so if you need translation into better coding tell me


print"do help to see instructions"
local function help()
print"w - forward"
print"s - backward"
print"a - left"
print"d - right"
print"e - up"
print"q - down"
print"fuel - show fuel level"
print"refuel - refuel"
print"f - attack"
print"u - place items into chest"
print"1 - mine up"
print"do help2 for next page!"
end
local function help2()
print"2 - mine ahead"
print"3 - mine down"
print"8 - place up"
print"9 - place ahead"
print"0 - place down"
print"30 - dig down then place down"
print"clear - clear"
print"shutdown - shut down"
end
local function r()
g = io.read()
end
local firstItem,lastItem = 1,16
while true do
x = io.read()
if x == "w" then
turtle.forward()
elseif x == "s" then
turtle.back()
elseif x == "a" then
turtle.turnLeft()
elseif x == "d" then
turtle.turnRight()
elseif x == "q" then
turtle.down()
elseif x == "e" then
turtle.up()
elseif x == "1" then
turtle.digUp()
elseif x == "2" then
turtle.dig()
elseif x == "3" then
turtle.digDown()
elseif x == "refuel" then
turtle.refuel()
elseif x == "8" then
turtle.placeUp()
elseif x == "9" then
turtle.place()
elseif x == "0" then
turtle.placeDown()
elseif x == "f" then
turtle.attack()
elseif x == "30" then
turtle.digDown()
sleep(0,5)
turtle.placeDown()
elseif x == "fuel" then
print("Fuel:-"..turtle.getFuelLevel() )
elseif x == "slot" then
print"enter slot number"
r()
turtle.select(tonumber(g))-- thanks Ninetainedo for this part :)/>/>
elseif x == "u" then
turtle.drop()
elseif x == "help" then
help()
elseif x == "help2" then
help2()
elseif x == "shutdown" then
print"good bye"
sleep(2)
os.shutdown()
elseif x == "clear" then
os.reboot()
else
print"unknown command, type 'help' for help"
end
end

NOTE:- this is NOT rednet! this is ran through a turtle console as "startup" or it will not work as planned!
i repeat! run this as STARTUP! i am not responsible for any turtle caniblisam!!

PS:- you need to have the fuel in the active slot to refuel! *this is to stop turtle using all wood, coal .etc*

Credits:- Ninetainedo:- Change slot script! … No one else besides myself and Ninetainedo

download!
[attachment=1112:startup.zip]
QuantumGrav #2
Posted 06 April 2013 - 10:41 AM
Nice, simple program!

When you are doing the 'dig down and then place down' command, you tell the program to 'sleep(0,5)' when I think it should be 'sleep(0.5)'. Have you tested the program?

A possible upgrade to your program might be the ability to to put a number after a command and then have it run that many times. For instance, 'w2' would go forward twice. To seperate the number from a command, you might use the 'string.sub(string, starting character, ending character)' command. It's really useful, and I suggest looking it up if you don't already know how to use it. To do this change, you might have to redesign what keys you have mapped to the commands, excluding numbers so there's no confusion. This suggestion isn't really necessary though, it's a good program either way.

Nice work!
calmilamsy #3
Posted 06 April 2013 - 10:42 AM
Nice, simple program!

When you are doing the 'dig down and then place down' command, you tell the program to 'sleep(0,5)' when I think it should be 'sleep(0.5)'. Have you tested the program?

A possible upgrade to your program might be the ability to to put a number after a command and then have it run that many times. For instance, 'w2' would go forward twice. To seperate the number from a command, you might use the 'string.sub(string, starting character, ending character)' command. It's really useful, and I suggest looking it up if you don't already know how to use it. To do this change, you might have to redesign what keys you have mapped to the commands, excluding numbers so there's no confusion. This suggestion isn't really necessary though, it's a good program either way.

Nice work!

it gives me errors when i do 0.5 so i use 0,5 and yes i have tested ALL of the commands it works all the time
calmilamsy #4
Posted 06 April 2013 - 10:58 AM
QuantumGrav:-


A possible upgrade to your program might be the ability to to put a number after a command and then have it run that many times. For instance, 'w2' would go forward twice.

that will be hard :/
calmilamsy #5
Posted 06 April 2013 - 11:07 AM
wait a second! i can make it prompt on how many blocks you whant it to go!

Making…
civilwargeeky #6
Posted 09 April 2013 - 06:34 PM
string.find() works well because then you can differentiate the string part from the number part.
calmilamsy #7
Posted 20 April 2013 - 09:56 AM
wait a second! i can make it prompt on how many blocks you whant it to go!

Making…

after a few errors i've finally put in the prompt for how far you need to go just need to test it on all commands (will be up on saturday/sunday)

p.s. ive been referring to my question to help me with the prompts because i have 90% bad memory :/
calmilamsy #8
Posted 21 April 2013 - 12:16 AM
after hunting for bugs i found out it didnt work after all… this is going to really annoy me….