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

Sensing turtle program help

Started by WestWindsDemon, 19 June 2015 - 08:19 AM
WestWindsDemon #1
Posted 19 June 2015 - 10:19 AM
HI everyone, I've been trying to make a program advanced wireless sensing turtles to use them as remote scouts using openPeripherals, so far I'm about 40% done, but I've stumbling on a little piece of it, the sensor. I get how the sensor works and I know how to pull the data from sensor.sonicScan(), but when I can't seem to build the table I want from this. What I basically want its a table consisting of 25 entries, corresponding from upper left to right, to the pixels in the remote screen consisting of A,B or C depending on the distance from the turtle, eg.(vsn={"A","B","C"}. I plan to send this table through modem.transmit() as textutils.serialize() to the control computer to "see" whats in front of the turtle. The current code that I have right now its skipping numbers and not completing the table at all. Please help me. Thanks in advance.


EDIT:I have updated the code, but its still not working. Please help me!


Spoiler

--:eye
--Variables & Such
s   = peripheral.wrap("left")
scn = s.sonicScan()
vsn = {}
y   = 2
K   = 1

--Start

for i=1, 25 do --going to do this 25 times
x = -2
for row=1, 5 do -- checking rows
for ii=1,3 do -- z lookup
for iii, v in pairs(scn) do -- goint ot cycle thru this 3 times
if v["z"] == ii and v["x"] == x and v["y"]== y then -- side we're looking at
if	  v["type"] == "SOLID" then
if	 ii == 1 then
vsn[K] = "A"
print("A")
elseif ii == 2 then
vsn[K] = "B"
print("B")
elseif ii == 3 then
vsn[K] = "C"
print("C")
else
textutils.slowPrint("ii "..ii.." error!")
end -- if ABC
elseif v["type"] == "AIR" then
vsn[K] = "O"
print("O")
else
end -- if solid
textutils.slowPrint("z: "..tostring(z))
end -- for xyz
end -- for iii
end -- for (ii) z lookup
   x = x + 1
end -- for rows
y = y - 1
K = K + 1
textutils.slowPrint("x: "..x..", y: "..y..", K: "..K..", vsn: "..tostring(vsn[K]))
end -- for 25

print("vsn type "..type(vsn))

KL = 0 --verifying vsn #
for BN, YU in pairs(vsn) do
KL=KL+1
end

print("pairs in vsn: "..KL)
--print(vsn[3])
Edited on 21 June 2015 - 02:01 PM
The_Cat #2
Posted 19 June 2015 - 06:37 PM
Its skipping the loop as you have commented out this line: "–for iii=1,3 do – z lookup"
WestWindsDemon #3
Posted 20 June 2015 - 01:12 AM
Yes, I was testing it before I copied, but still without skipping it's messing up.