Page 1 of 1

dt is a table value?

Posted: Sat Nov 12, 2016 7:47 pm
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.

Re: dt is a table value?

Posted: Sat Nov 12, 2016 7:59 pm
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).

Re: dt is a table value?

Posted: Sat Nov 12, 2016 8:10 pm
by Doctory
i cant even use the library i made properly, thanks for the help!