Posted 30 September 2013 - 03:02 PM
Why am I getting "attempt to index field '?' (a boolean value)"?
What I'm trying to do is create a program that can do ray tracing.
Code
What my code is meant to do is create a 'ray' that keeps going until it ether hits something
or when't as far as its meant to go.
My code is working until it read 'world[a][c]' then it gives me the error above.
If someone else posted a problem just like this please tell me because I looked for a long time.
P.S. It is hard coded to work with a computer screen only for a reason
What I'm trying to do is create a program that can do ray tracing.
Code
Spoiler
local w = 52
local h = 19
local world = {}
function newWorld(sizeXmin, sizeXmax, sizeYmin, sizeYmax, sizeZmin, sizeZmax)
for a=sizeXmin,sizeXmax do
world[a] = {}
for b=sizeYmin,sizeYmax do
world[a][b] = {}
for c=sizeZmin, sizeYmax do
world[a][b][c] = false
end
end
end
end
function importModel(name, model)
world[name] = model
end
function newRay(x, y, z, xD, yD, zD, d)
print("x:"..tostring(x).." y:"..tostring(y).." z:"..tostring(z))
local xC = x
local yC = y
local zC = z
for a=1,d do
for b,c in pairs(world) do
print(world[b][x][y][z])
if world[b][x] == nil then
elseif world[b][x][y] == nil then
elseif not world[b][x][y][z] then
print("x:"..tostring(x).." y:"..tostring(y).." z:"..tostring(z).." value:"..world[b][x][y][z])
return world[b][x][y][z]
end
xC = xC + xD
yC = yC + yD
zC = zC + zD
x = math.floor(xC)
y = math.floor(yC)
z = math.floor(zC)
end
end
return false
end
function rays(x, y, z, xD, yD, zD, d, a)
local pointX = x-(xD*a)
local pointY = y-(yD*a)
local pointZ = z-(zD*a)
local sX = x
local sY = y
local cenX = math.floor(w/2)
local cenY = math.floor(h/2)
local mX = cenX*(-1)
local mY = cenY*(-1)
local screen = {}
for a=mX,cenX do
screen[sY] = {}
for b=mY,cenY do
print(tostring(screen[sY][sX]).." x:"..tostring(x).." y:"..tostring(y).." z:"..tostring(z).." pX:"..tostring(pointX+a).." pY:"..tostring(pointY+B)/>/>.." pZ:"..tostring(pointZ+a))
screen[sY][sX] = newRay(x, y, z, math.floor(pointX+a), math.floor(pointY+B)/>/>, math.floor(pointZ+a), d)
sX = sX + 1
end
sY = sY + 1
end
return screen
end
newWorld(1, 5, 1, 6, 1, 7)
local m = {}
m[1] = {}
m[1][1] = {}
m[1][1][1] = 3
m[1][2] = {}
m[1][2][1] = 2
importModel("m", m, 1, 1, 1)
local a = rays(1, 1, 1, 1, 1, 0, 8, 5)
or when't as far as its meant to go.
My code is working until it read 'world[a][c]' then it gives me the error above.
If someone else posted a problem just like this please tell me because I looked for a long time.
P.S. It is hard coded to work with a computer screen only for a reason