attempt to preform arithmetic on field "xvel" (a nil value)

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
Omnikariz
Prole
Posts: 2
Joined: Wed Jan 29, 2014 5:15 am

attempt to preform arithmetic on field "xvel" (a nil value)

Post by Omnikariz »

I'm getting this error in my player.lua, inside my player.physics(dt), and I'm not really sure how to fix this with the error.

Code: Select all

function player.physics(dt)
	player.x = player.x + player.xvel * dt
	player.y = player.y + player.yvel * dt
	player.xvel = player.xvel * (1 - math.min(dt*friction, 1))
end
I've gotten this error before and I really don't know at all what to do about it.

.LOVE For the game is attached, thanks in advance.
Attachments
alot.love
The .LOVE for the game
(924 Bytes) Downloaded 150 times
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: attempt to preform arithmetic on field "xvel" (a nil val

Post by micha »

This error means that the variable player.xvel does not exist at the time when the corresponding line is executed. Add

Code: Select all

player.load()
to you love.load and the error is gone (you will get a different error then, because friction is not defined).
User avatar
Omnikariz
Prole
Posts: 2
Joined: Wed Jan 29, 2014 5:15 am

Re: attempt to preform arithmetic on field "xvel" (a nil val

Post by Omnikariz »

Yeah, thanks, shortly after posting this I found out the problems. Thanks anyway though.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 10 guests