So I just started Object Oriented Programming but I run to this annoying problem. I keep getting warnings saying that setmetatable should take a table and that animationTracks cannot be added to a table.
--!strict
local Creature = require(script.Parent)
local Enemy = {}
Enemy.__index = Enemy
setmetatable(Enemy, Creature)
function Enemy.new(model: Model)
local newEnemy = Creature.new(model)
setmetatable(newEnemy, Enemy)
newEnemy.animationTracks = {}
return newEnemy
end
return Enemy
--!strict
local Movement = {}
Movement.__index = Movement
function Movement.new(model: Model, path: Folder)
local newMovement = {}
setmetatable(newMovement, Movement)
-- ...
return newMovement
end
function Movement:Start()
-- ...
end
return Movement
local movement = Movement.new(model, path)
movement:Start()
This does not only happen to Start(), it happens to all functions really.
You can try using assertion to assert that movement is of proper type.
type movement = {
alignPosition: AlignPosition;
lastSpeed: number;
-- etc
}
local movement = Movement.new(model, path) :: movement -- use 2 colons to assert that it's of proper type
movement:Start()