13 posts
Posted 16 January 2014 - 05:36 PM
Hello everyone, I had a crazy idea for a turtle program today, but I need a tip.
First of all I haven't started writting the program, but i'll make it store variables on movement.
Something like this: if turtle.Up() then y + 1
and use that information to check if has enough fuel to go back
if y + x == turtle.getFuelLevel() then
–go back or something
else
–code
I need a tip, like I said, can I make it read a command while in a while true loop?
Let's say I want to get the number of block it's travelled by using print(y.. "and" ..x) but only when I type something like "GreatShooter", is that possible?
Can't write it at the moment, server having problems
Edited on 16 January 2014 - 04:39 PM
1281 posts
Posted 16 January 2014 - 05:49 PM
Running after turtles on the move and inputting stuff into them is really annoying, so im gonna assume you intend to input these while he's stationairy.
This means we can do this the most basic way possible
while true do
local command = string.lower(read()) -- requests user input, stores the input as all lower case in the variable command
if command == "print coords" then
--print coordinates here
elseif command == "something else" then
--do something else
end
end
Edited on 16 January 2014 - 04:49 PM
13 posts
Posted 16 January 2014 - 05:51 PM
The thing is, I don't want them to move on command, I want to make them work at all times and only give me the data when requested
1281 posts
Posted 16 January 2014 - 06:12 PM
So you intend to chase his ass down and input the command, or request it over rednet? If it's the former, i would suggest just having the info printed to the screem on the turtle at all times.
13 posts
Posted 16 January 2014 - 06:24 PM
Basicly a debug in case of chunkloading problems
1281 posts
Posted 16 January 2014 - 06:43 PM
That dosen't really answer the question, do you want the information displyaed on the turtle, or remotely?
110 posts
Posted 17 January 2014 - 11:29 AM
A "smart" mining turtle will typically use rednet to talk back to a stationary computer, feeding it information, such as location, how many inventory slots are free, progress on its task, remaining fuel, etc.. It would also receive commands from this stationary computer, such as "go here", "pause at surface", "do something else now", or "come back".
7083 posts
Location
Tasmania (AU)
Posted 17 January 2014 - 09:13 PM
Long story short, the
parallel API would be the way to go here - it allows you to run two functions side by side. This is only needed because both turtle movements and collection of user input rely on events, and each system will otherwise deny the other of its required events in order to operate itself (unless you go way, way out of your way to get them to co-operate) - the parallel API grants both functions a complete copy of the event queue to do as they like with, providing an easy way out.
-- Pre-declare some variables that can be accessed anywhere in the script.
local x,y,z,direction
------------------------------------------------------------------------------
-- Perhaps call a GPS server here to work out where the turtle started off. --
------------------------------------------------------------------------------
-- Some movement functions.
local function forward()
if turtle.forward() then
-- Add to or subtract from your location variables, depending on facing.
return true
else
return false
end
end
-- ... and create more similar functions for other movements.
local function doTurtleWork()
-- Code here to make the turtle do what you want.
-- This code uses your pre-made moving functions instead of turtle.forward(), etc.
end
local function report()
while true do
-- Code here either waits for the user to type something,
-- or for a rednet message, or whatnot.
-- Gives replies based on your location variables or whatever.
end
end
parallel.waitForAny(doTurtleWork, report) -- Start both functions running side by side.
-- Waits for either to finish.
13 posts
Posted 18 January 2014 - 07:38 AM
I think the paralel API would do it, yes I want to chase his ass down in case of chunkloading problems. Thanks for the answers everyone.
Edited on 18 January 2014 - 06:40 AM