my function doesnt work... but why?

i proofed everything with print() arguments… it still doesnt work. the error says that the x and y coordinates are nil, but they arent! proofed! (maybe it will help you, the error says that there is something wrong with the translate in the debug draw, it says that the translate arguments are nil → it says body.x & body.y are nil, but yeah… they are not!)

the function:

function createBlock(old_x1,old_y1,old_x2,old_y2)
    local n = #blocks + 1
    
    new_x1 = old_x1 + 400
    new_y1 = old_y1 + 200
    new_x2 = old_x2 + 400
    new_y2 = old_y2 + 200
    print("old_x1 = "..old_x1)
    print("new_x1 = "..new_x1)
    print()
    print("old_y1 = "..old_y1)
    print("new_y1 = "..new_y1)
    print()
    print("old_x2 = "..old_x2)
    print("new_x2 = "..new_x2)
    print()
    print("old_y2 = "..old_y2)
    print("new_y2 = "..new_y2)
    print()
    
    blocks[n] = physics.body(POLYGON,
        vec2(new_x1,new_y1),
        vec2(new_x2,new_y1),
        vec2(new_x2,new_y2),
        vec2(new_x1,new_y2))
    blocks[n].x = new_x1
    blocks[n].y = new_y1
    PDD:addBody(blocks[n])
end

i called this function like this:

createBlock(0,0,10,100)

your maxiking :wink:

Try to cut the code down to the smallest code that generates the error. I usually manage to get hard to find errors like this doing that. And in the worst case you have a small piece of code that you can post as a bug report.

Can you please post the code for the PDD:addBody function?

i called the PhysicsDebugDraw PDD, so its the basic debugDraw

Ah OK I didn’t know about PhysicsDebugDraw, I had to Google it :). With that in place this function works ok for me when I call it like you suggested. Maybe there’s something else you’re assuming I would know to do that I’m not doing? Basically it’s best if you follow ruilov’s suggestion and paste a fully functional example which replicates the issue when it’s run. Then others can focus on solving the issue rather than trying to figure out how to replicate it (and in my case, failing) :slight_smile: