Posted 31 March 2014 - 12:17 AM
Hello!
I'm new to the forums, and already it has been a great help for me but i need to ask something i couldn't find anywhere else..
I'm trying to compare 2 arrays with each other and make an other one with that information. If the value in array 'a' is the same as 'b[j]' then i want that NOT in my new array.. So in my new array are only all unique value's (that's the idea).
The steps I took in trying to achieve it was a for loop in 'b' within a for loop in 'a'. If there was a same value then he would over-write array 'c'[key] with a 'nil' value.
And at the final stage I made a for loop for the 'c' array and for every 'key' i would add a new value in array 'e'.
Problem:
The problem is that it does not work..
What does not work? I'm not sure if he do makes the 'c' or 'e' array correctly (although i do not think so (nearly certain)) the comparing does not work. It does not filter out the unique value's.. ..instead it just passes everything.
The comparing function and make the 'c'/'e' array function is:
The 'b' array he calculates itself.. using this code:
The 'a' array he get's from an other computer using rednet.receive()/send()
Full code: client / server
I'm new to the forums, and already it has been a great help for me but i need to ask something i couldn't find anywhere else..
I'm trying to compare 2 arrays with each other and make an other one with that information. If the value in array 'a' is the same as 'b[j]' then i want that NOT in my new array.. So in my new array are only all unique value's (that's the idea).
The steps I took in trying to achieve it was a for loop in 'b' within a for loop in 'a'. If there was a same value then he would over-write array 'c'[key] with a 'nil' value.
And at the final stage I made a for loop for the 'c' array and for every 'key' i would add a new value in array 'e'.
Problem:
What does not work? I'm not sure if he do makes the 'c' or 'e' array correctly (although i do not think so (nearly certain)) the comparing does not work. It does not filter out the unique value's.. ..instead it just passes everything.
The comparing function and make the 'c'/'e' array function is:
function CompareMine()
r = 1
c = b
d = 1
e = {}
f = 0
for i in ipairs(a) do
for j in ipairs(B)/>/>/> do
if a[i][1] == b[j][1] and a[i][3] == b[j][3] then
c[i] = {}
c[i][1] = nil
c[i][2] = nil
c[i][3] = nil
end
end
end
for i in ipairs(B)/>/>/> do
r = r + 1
end
for i = 1, r do
if c[i][1] == nil then
else
e[d] = {}
e[d][1] = c[i][1]
e[d][2] = MaxAvgGround
e[d][3] = c[i][3]
d = d + 1
end
end
for i in ipairs(e) do
print(e[i][1].. ' '.. e[i][2].. ' '.. e[i][3])
f = f + 1
end
print("available for mining: "..f)
end
The 'b' array he calculates itself.. using this code:
function CalculateMine()
b = {}
i = 1
p = 1
x = MineLocationX
z = MineLocationZ
xplus = x + PlusX
zplus = z + PlusZ
while calmine() do
b[i] = {}
b[i][1] = x
b[i][2] = y
b[i][3] = z
i = i + 1
end
print("Number of possible shafts: " .. (i-1))
end
function calmine()
if (x + 5) <= xplus and i ~= 1 then
x = x + 5
return true
elseif i == 1 then
return true
else
x = MineLocationX
if p == 1 then
o = 0
elseif p == 2 then
o = 2
elseif p == 3 then
o = 4
elseif p == 4 then
o = 1
elseif p == 5 then
o = 3
p = 0
end
x = x + o
p = p + 1
if (z + 1) <= zplus then
z = z + 1
return true
else
return false
end
end
end
The 'a' array he get's from an other computer using rednet.receive()/send()
function Answer()
print("turtle "..org_name.." asked for "..message)
--name
--x, y, z
i = 1
s = fs.open(message, 'r')
while i ~= datacount do
coords = s.readLine()
if coords ~= nil then
print("sended "..coords.." to "..org_name)
rednet.send(org_name, coords)
os.sleep(0.1)
end
i = i + 1
end
s.close()
end
Full code: client / server