Jump to content


popdog15's Content

There have been 7 items by popdog15 (Search limited from 10-February 22)


By content type

See this member's

Sort by                Order  

#216711 Turtle turning to a certain direction

Posted by popdog15 on 10 May 2015 - 03:08 PM in Ask a Pro

View PostBomb Bloke, on 10 May 2015 - 11:04 AM, said:

View Postpopdog15, on 09 May 2015 - 05:44 AM, said:

My problem lies at line 257 and later upon calling it at 277. I'm telling the turtle to get an item to the east when it's facing north, and in theory, it should just turn left 3 times and then stop, but it doesn't. It just keeps on turning no matter what. No idea why. Maybe the current 'pos' is not accurate? I don't know.

So around line 257, we have:

function figureOutTurn(newf)
		while f ~= newf do
		turtle.turnLeft()
		end
end

... a loop that'll repeat so long as f isn't newf. And since it never bothers to change those variables, it's indeed going to keep going for quite a while...

Did you intend to call your changeTurtle() function from there?
Oh, yeah, that'd be the problem. I'm silly sometimes, thanks.



#216674 Turtle turning to a certain direction

Posted by popdog15 on 10 May 2015 - 08:11 AM in Ask a Pro

View Postflaghacker, on 10 May 2015 - 07:32 AM, said:

View Postpopdog15, on 10 May 2015 - 06:59 AM, said:

Bump as of edit? (If allowed?)

Pleaso don't edit your original post, just write a new one. It's going to become a mess like this.
I thought this was better than flooding the "Ask a Pro" board, but all right.



#216670 Chatbox

Posted by popdog15 on 10 May 2015 - 07:05 AM in Ask a Pro

There is a limit to the distance within the config last I checked.



#216669 Turtle turning to a certain direction

Posted by popdog15 on 10 May 2015 - 06:59 AM in Ask a Pro

Bump as of edit? (If allowed?)



#216618 Turtle turning to a certain direction

Posted by popdog15 on 09 May 2015 - 04:31 PM in Ask a Pro

View Postvalithor, on 09 May 2015 - 03:48 PM, said:

View Postpopdog15, on 09 May 2015 - 03:28 PM, said:

View PostBomb Bloke, on 09 May 2015 - 08:09 AM, said:

Flush simply ensures that any data you've queued to be written to disk, gets written to disk before the script goes any further. Normally data you've requested be written goes into a buffer to be actually written when the VM thinks it's worth kicking the HDD into action (sending one big write request is more efficient than ordering lots of little ones). Closing a file automatically flushes it, but, in cases where you think your script might crash in between your write commands and your close call, you can request it manually. Of course, if you've simply opened the file and haven't made any write calls yet, flushing does nothing (and in cases where you're closing the files directly after ordering writes, it effectively does nothing).

It seems you never define "newF". The fourth line of your "pos" file will quickly become blank, and "f" will thus become an empty string.

Frankly my recommendation is to forget about having your turtles "remember" their states in between boots, and simply code them to figure it out each time they boot up based on a GPS setup. There's no point in flogging your hard drive when you'll never move out of range of a satellite system.

Here's an example of the sort of code most all of my turtle scripts execute on startup:

local pos, facings = {}, {"north","east","south","west"}

-- Ping the GPS servers until I get a valid reading:
do
		local tempx, tempy, tempz
		while tempx == nil or tempy == nil or tempz == nil do
				tempx, tempy, tempz = gps.locate(5)
				sleep(5)
		end

		while not turtle.forward() do while not turtle.turnLeft() do end end
		pos.x,pos.y,pos.z = gps.locate(5)

		if pos.x < tempx then pos.direction = 4
		elseif pos.x > tempx then pos.direction = 2
		elseif pos.z < tempz then pos.direction = 1
		else pos.direction = 3 end
end

print("I'm at "..pos.x..","..pos.y..","..pos.z..", I have "..turtle.getFuelLevel().." fuel and I'm facing "..facings[pos.direction]..".")

I then just have them update the variables in the pos table as they move around.
Oh. I thought it flush purged the file of it's contents. I changed it around so that it deletes the 'pos' file every time and just re-writes it, and with that, it works now.

Just so you know by opening a file in write mode using the fs api (fs.open(file,"w")) it will delete the contents automatically. The only reason the contents are not being deleted when you open it is because you are using append mode which adds the information to the end.

So instead of deleting the file you can just do this:
local h = fs.open(file,"w") -- because it is opened in "w" mode it will delete all contents
h.writeLine(stuff)
h.close()

Append mode or "a" mode will just add whatever you want to write to the end of the file.
Oh. All righty then, thanks.



#216614 Turtle turning to a certain direction

Posted by popdog15 on 09 May 2015 - 03:28 PM in Ask a Pro

View PostBomb Bloke, on 09 May 2015 - 08:09 AM, said:

Flush simply ensures that any data you've queued to be written to disk, gets written to disk before the script goes any further. Normally data you've requested be written goes into a buffer to be actually written when the VM thinks it's worth kicking the HDD into action (sending one big write request is more efficient than ordering lots of little ones). Closing a file automatically flushes it, but, in cases where you think your script might crash in between your write commands and your close call, you can request it manually. Of course, if you've simply opened the file and haven't made any write calls yet, flushing does nothing (and in cases where you're closing the files directly after ordering writes, it effectively does nothing).

It seems you never define "newF". The fourth line of your "pos" file will quickly become blank, and "f" will thus become an empty string.

Frankly my recommendation is to forget about having your turtles "remember" their states in between boots, and simply code them to figure it out each time they boot up based on a GPS setup. There's no point in flogging your hard drive when you'll never move out of range of a satellite system.

Here's an example of the sort of code most all of my turtle scripts execute on startup:

local pos, facings = {}, {"north","east","south","west"}

-- Ping the GPS servers until I get a valid reading:
do
		local tempx, tempy, tempz
		while tempx == nil or tempy == nil or tempz == nil do
				tempx, tempy, tempz = gps.locate(5)
				sleep(5)
		end

		while not turtle.forward() do while not turtle.turnLeft() do end end
		pos.x,pos.y,pos.z = gps.locate(5)

		if pos.x < tempx then pos.direction = 4
		elseif pos.x > tempx then pos.direction = 2
		elseif pos.z < tempz then pos.direction = 1
		else pos.direction = 3 end
end

print("I'm at "..pos.x..","..pos.y..","..pos.z..", I have "..turtle.getFuelLevel().." fuel and I'm facing "..facings[pos.direction]..".")

I then just have them update the variables in the pos table as they move around.
Oh. I thought it flush purged the file of it's contents. I changed it around so that it deletes the 'pos' file every time and just re-writes it, and with that, it works now.



#216576 Turtle turning to a certain direction

Posted by popdog15 on 09 May 2015 - 05:44 AM in Ask a Pro

All right. I'm working on a to be storage program that counts items and can pull them out of storage using a network of turtles. So far I have written a framework for the turtle, and after that I will be writing a server and client. My turtle code is currently: Code

My problem lies at line 257 and later upon calling it at 277. I'm telling the turtle to get an item to the east when it's facing north, and in theory, it should just turn left 3 times and then stop, but it doesn't. It just keeps on turning no matter what. No idea why. Maybe the current 'pos' is not accurate? I don't know.



Previous issue that is resolved.
Spoiler