I haven’t touched my code in a while and decided to pick my project back up. I was trying to add another mesh (a coin) and I keep getting the error "attempt to index local ‘self’ (a null value). My guess would be that I screwed something up in Coin:init() but I’m not sure.
error: [string “Coin = class()…”]:75: attempt to index local ‘self’ (a nil value)
Here is the code (I know that it’s messy)
Coin = class()
function Coin:init(x,y,z)
print(“initializing coin”)
self.posx = x
self.posy = y
self.posz = z
self.w = 10
self.h = 10
self.d = 10
self.width=self.w
self.height=self.h
self.depth=self.d
self.width=self.w
self.height=self.h
self.depth=self.d
self.tex="Documents:ground"
if self.r~=nil then self.texR=self.r else self.texR={0,0,1,1} end
self.v = {
vec3(self.posx,self.posy,self.posz),
vec3(self.posx+self.w,self.posy,self.posz),
vec3(self.posx+self.w,self.posy+self.h,self.posz),
vec3(self.posx,self.posy+self.h,self.posz),
vec3(self.posx,self.posy,self.posz+self.d),
vec3(self.posx+self.w,self.posy,self.posz+self.d),
vec3(self.posx+self.w,self.posy+self.h,self.posz+self.d),
vec3(self.posx,self.posy+self.h,self.posz+self.d)
}
self.cubeverts = {
-- Front, Right, Back, Left, Top, Bottom
self.v[1], self.v[2], self.v[3], self.v[1], self.v[3], self.v[4],
self.v[2], self.v[6], self.v[7], self.v[2], self.v[7], self.v[3],
self.v[6], self.v[5], self.v[8], self.v[6], self.v[8], self.v[7],
self.v[5], self.v[1], self.v[4], self.v[5], self.v[4], self.v[8],
self.v[4], self.v[3], self.v[7], self.v[4], self.v[7], self.v[8],
self.v[5], self.v[6], self.v[2], self.v[5], self.v[2], self.v[1],
}
self.BL=vec2(self.texR[1],self.texR[2]) --bottom left
self.BR=vec2(self.texR[3],self.texR[2]) --bottom right
self.TR=vec2(self.texR[3],self.texR[4]) --top right
self.TL=vec2(self.texR[1],self.texR[4]) --top left
self.cubetexCoords = {}
for i=1,6 do
table.insert(self.cubetexCoords,self.BL)
table.insert(self.cubetexCoords,self.BR)
table.insert(self.cubetexCoords,self.TR)
table.insert(self.cubetexCoords,self.BL)
table.insert(self.cubetexCoords,self.TR)
table.insert(self.cubetexCoords,self.TL)
end
self.ms = mesh()
--ms.shader=shader("Documents:Test")
self.ms.vertices = self.cubeverts
--self.ms.texture = self.tex
--self.ms.texCoords = self.cubetexCoords
--self.ms.shader = shader("Documents:3d")
--self.ms.shader.texture = "Documents:ground"
self.ms:setColors(0,255,0,255)
--self.ms.shader.lightAngle = vec3(0,-200,0)
print("finished")
return self.ms
end
function Coin:draw()
self.ms:draw()
end