dt is a table 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
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

dt is a table value?

Post by Doctory »

hello everyone,
im having a problem when trying to use dt to preform an arithmetic with it, but love throws an error on me saying its a table function:
Image

hope anyone here is able to fix it. thanks in advance. .love is attached.
Attachments
error.love
(9.24 KiB) Downloaded 217 times
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: dt is a table value?

Post by pgimeno »

You're using dot notation for defining the update function, but calling it with colon notation.

When calling a function, using a colon is equivalent to calling it with the table as the first argument. For example:

Code: Select all

player:update(dt)
is equivalent to:

Code: Select all

player.update(player, dt)
So, you're passing the player table as the first parameter, because you use colon notation when you do this:

Code: Select all

states.states[states.currentState]:update(dt)
The solution is simple: just use a colon in the definition too, like this:

Code: Select all

function player:update(dt)
That's equivalent to:

Code: Select all

function player.update(self, dt)
so you can use either, though I'd say the former is preferred in this case.

Edit: Note that it will err again because you have the same issue in src/states/game.lua - just replace function game.update(dt) and player.update(dt) with function game:update(dt) and player:update(dt).
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: dt is a table value?

Post by Doctory »

i cant even use the library i made properly, thanks for the help!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 49 guests