OOP problem when using beginCon. [Fixed it myself]

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
NoreoAlles
Party member
Posts: 107
Joined: Mon Jan 03, 2022 5:42 pm

OOP problem when using beginCon. [Fixed it myself]

Post by NoreoAlles »

For some reason, this code does not work.

Code: Select all

function Block:beginCon(a, b, collision)
    if a == self.fixture and b == pong.fixture then  
        table.remove(ActiveBlocks, instance)
    elseif b == self.fixture and a == pong.fixture then  
        table.remove(ActiveBlocks, instance)
    end
end 

function Block:beginConAll(a,b, collision)
    for i, instance in ipairs(ActiveBlocks) do 
        instance:beginCon(a, b, collision)
    end
end
It seems to be the "self.fixture" that is causing the trouble because when its just

Code: Select all

function Block:beginCon(a, b, collision)
        table.remove(ActiveBlocks, instance)
end 
it works.
Block is a OOP object, or how you call it, this is how i declared it

Code: Select all

Block = {}
Block.__index = Block 
ActiveBlocks = {}

function Block:new(x, y, w, h, r, g, b)
    local instance = setmetatable({}, Block)
    instance.x = x 
    instance.y = y 
    instance.w = w 
    instance.h = h
    instance.r = r 
    instance.g = g 
    instance.b = b
    instance.body = love.physics.newBody(world, instance.x, instance.y, "static")
    instance.shape = love.physics.newRectangleShape(instance.w, instance.h)
    instance.fixture = love.physics.newFixture(instance.body, instance.shape)
    table.insert(ActiveBlocks, instance)
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 13 guests