Today i am making my own timer system in Love2d, but in one function to change the delay of the timer, when i use the love.timer.getFPS() it returns me a table and when i use it on a love.graphics.print() it returns me a number. This is actually what i am doing:
--Timer returning function
function Timer(frames)
return {
frames = frames,
update = function(fr)
frames = fr
end
}
local t = Timer(60)
function love.update(dt)
t:update(love.timer.getFPS()) -- This love.timer.getFPS returns me a table
end
function love.draw()
love.graphics.print(love.timer.getFPS(), 0, 20) -- This returns me a number
end
I am using Löve2d 0.11.0.
This is the simplified code, the .love is attached to the post.
You are another member of the "not knowing how/when to use the colon (:) notation club"!
Now, that's not something to be sad about, but learning how it works helps!
Basically, you defined your update function (in the Timer constructor function) to have one parameter, fr.
Then, you are calling it with the colon notation, which will pass a hidden parameter, the table you called the function on, into the function before any other parameters.
In short, you are setting t.frames to be t itself.
the simplest fix would be to swap : out for a simple dot (.)
alternatively, if you do want "object orientation" flavor in your code, you could just write another parameter before fr in that function definition (call it self or obj or whatever you want, it doesn't matter, in this case, let's go with self), and set self.frames to fr instead!
Me and my stuff True 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.