CirclePit = class()
function CirclePit:init()
self.units = {}
self.r = 600
delPi = math.rad(1)
CirclePit:addUnit()
end
function CirclePit:addUnit()
local angle = 0
table.insert(self.units, Unit(angle))
end
Compiler says table.insert gets nil instead of table.
I did the same thing in other projects and it worked, what’s wrong here?
Upd
function setup()
displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)
pit = CirclePit()
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(255, 255, 255, 255)
-- This sets the line thickness
sprite("Planet Cute:Rock", WIDTH/2, 120)
noStroke()
smooth()
fill(255, 42, 0, 255)
ellipse(WIDTH/2, -HEIGHT, HEIGHT *2 + 200)
pit:draw()
-- Do your drawing here
end
@Vlayan Can we see the code where you use the CirclePit? Make sure you’re just doing something like myVariable = CirclePit() and NOT something like myVariable = CirclePit:init() or myVariable = CirclePit.init()
(I mean not the function name but when you call it in the CirclePit:init() )
what you’re doing is creating an object, that object has the table units created, but then you call a function that calls self.units, but you need to call the function from that object you just created, which is done by using self:function()m
or if you’d need to call it outside of the class, it would be object:function()