Can someone help me with this error

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
LuciansLÖVEforcoding
Prole
Posts: 2
Joined: Wed Dec 28, 2022 5:59 am

Can someone help me with this error

Post by LuciansLÖVEforcoding »

I am using the love physics and I am getting this error
Error

main.lua:7: bad argument #2 to 'newFixture' (Shape expected, got nil)


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newFixture'
main.lua:7: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'

although i am not sure what is wrong. My code looks like this

function love.load()
game = love.physics.newWorld(0, 0, true)
playerimage = love.graphics.newImage('assets/PLAYER.png')
player = love.physics.newBody(game, 500, 500, "dynamic")
player:setFixedRotation(true)
playerhitbox = love.physics.newCircleShape(95)
PlayerFixture = love.physics.newFixture(player, circle, 1)
end
if someone is able to help me, then please tell me what is wrong
User avatar
ddabrahim
Party member
Posts: 201
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: Can someone help me with this error

Post by ddabrahim »

I have no experience with physics. but according to the error message at line 7 in main.lua the second argument of newFixture() should be a type of Shape but it is nil.

newFixture() takes 3 arguments (body, shape, density)
A shape is a solid 2d geometrical objects which handle the mass and collision of a body.
For example ChainShape, CircleShape, RectangleShape.

You missing the shape, maybe you just spelled it wrong or you did not create one.

You can read more about it in the docs:

https://love2d.org/wiki/love.physics.newFixture
https://love2d.org/wiki/Shape

If it does not help, post your code or a small project we can try.
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: Can someone help me with this error

Post by Andlac028 »

You define playerhitbox and then use circle, use either only playerhitbox or circle.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Can someone help me with this error

Post by zorg »

yeah, doing the below line fixes it probably, since, you know, you named your circle shape playerhitbox...:
PlayerFixture = love.physics.newFixture(player, playerhitbox, 1)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
LuciansLÖVEforcoding
Prole
Posts: 2
Joined: Wed Dec 28, 2022 5:59 am

Re: Can someone help me with this error

Post by LuciansLÖVEforcoding »

Thank you guys for the help!
I am no longer getting any errors
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest