Posted 27 August 2016 - 01:05 AM
This should be fun to explain!
So, I believe this is my first time posting on this forum and I'm not entirely sure if there's some etiquette besides not asking obvious questions like "How do I lua?". So in advance, I'm sorry if I broke etiquette.
I have a program that uses a Scanner wrapped to the turtle to scan tiles around it. I've been testing the mechanics and found that the scans around the turtle are not relative to the turtle, rather, relative to the world centered on the turtle. So, that means the turtle's direction has no impact on the scan, just what coordinates it has in the world. So, I made a huge key table, like you would if you want to have faster access times, converted all the default scan indexes into coordinates. And now I can scan under the turtle without using turtle.detectDown(). So, here's the issue.
I wanted to test it's reliability on a loop basis. And here's where i'm totally stumped. I have highly modified turtle code so, me pasting code, would REALLY break etiquette, and unless there's enough interest I wont post any code. But, here's the code that is being weird.
That is a test line I wrote. So the setup is, the turtle moves forward until it finds a hole in the floor. But, what actually happens is it stops after it passes the hole, adjacent to it, right next to it, [F][F][H][T]. Floor, Hole, Turtle. Any ideas?
Edit
If I use os.sleep(0.25), after the bot.move(), not before, this whole problem goes away, so clearly there's a particular speed element to this. Oddly enough, I think the code is executing too fast after bot.move().
So, I believe this is my first time posting on this forum and I'm not entirely sure if there's some etiquette besides not asking obvious questions like "How do I lua?". So in advance, I'm sorry if I broke etiquette.
I have a program that uses a Scanner wrapped to the turtle to scan tiles around it. I've been testing the mechanics and found that the scans around the turtle are not relative to the turtle, rather, relative to the world centered on the turtle. So, that means the turtle's direction has no impact on the scan, just what coordinates it has in the world. So, I made a huge key table, like you would if you want to have faster access times, converted all the default scan indexes into coordinates. And now I can scan under the turtle without using turtle.detectDown(). So, here's the issue.
I wanted to test it's reliability on a loop basis. And here's where i'm totally stumped. I have highly modified turtle code so, me pasting code, would REALLY break etiquette, and unless there's enough interest I wont post any code. But, here's the code that is being weird.
while bot.scan[vector.new(0,-1,0)] do bot.move() end
function Scanner.new(Peripheral, Cardinal)
local Meta = Scanner
local self = setmetatable({ device = Peripheral, scanData = nil, type = nil, tracking = {} },Scanner)
function Scanner:__index(key)
if key.type == "vector" then
if not self.scanData then
self.scanData = self.device.sonicScan()
end
if self.type then
return self.scanData[map[key.x][key.y][key.z]].type == self.type
end
return self.scanData[map[key.x][key.y][key.z]]
else
return Meta[key]
end
end
return self
end
this.move = function (y,x)
...
if this.scan.scanData then
this.scan.scanData = nil
end
...
end
That is a test line I wrote. So the setup is, the turtle moves forward until it finds a hole in the floor. But, what actually happens is it stops after it passes the hole, adjacent to it, right next to it, [F][F][H][T]. Floor, Hole, Turtle. Any ideas?
Edit
If I use os.sleep(0.25), after the bot.move(), not before, this whole problem goes away, so clearly there's a particular speed element to this. Oddly enough, I think the code is executing too fast after bot.move().
Edited on 26 August 2016 - 11:35 PM