Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[SOLVED] Mesh problem

edited February 2014 in Questions Posts: 49

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

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 6,828

    @1980geeksquad I tried your Coin class and it prints "initializing coin" then "finished". Could you show the line 75 that's giving the error. Line 75 in your code won't be line 75 in my code. Since I'm not getting an error, I can't say why you are.

  • It says it on the "self.ms:draw()"

  • dave1707dave1707 Mod
    edited February 2014 Posts: 6,828

    @1980geeksquad In my setup I'm calling c=Coin(300,600,0). In my draw() I'm calling c:draw() . That's calling self.ms:draw() . I'm getting a small green square showing at location 300,600 on the screen.

  • @dave1707 Then it must be something on my end. Thanks for the help. I know that the error isn't in this part anymore. I'll update if I fix it.

  • @dave1707 I feel like an idiot now... I used coins[i].draw() instead of coins[i]:draw()...
    I was literally stuck on this for a few days now.

  • IgnatzIgnatz Mod
    Posts: 5,396

    1980geeksquad - I did that often, early on, was very annoying

  • @1980geeksquad lolz. That was the one that kept me up for two nights when I first started. Welcome to the club. ;)

Sign In or Register to comment.