The problem is you're using global variables inside of your class functions.
In game.lua, you write:
Code: Select all
function Game:new()
require "platformSpawn"
platform = Platform()
end
platform is in the global scope by default.
Inside platformSpawn.lua, there is also this function:
Code: Select all
function createPlatform()
platform =
{
x = love.graphics.getWidth(),
y = love.math.random(0, love.graphics.getHeight()),
width = 256,
height = 16
}
return platform
end
The platform inside of there refers to the same platform in the global scope, so it overwrites whatever
platform was previously. You can confirm this by printing out
platform in createPlatform before and after creating the table.
Since createPlatform is called during update, when it moves on to draw, platform is now a table that doesn't have a draw function. That's why you get that specific error.
So, you could fix it by using local variables instead of global variables wherever possible, something like:
Code: Select all
function createPlatform()
local platform = { ... }
return platform
end