I have a class called Walk which inherent from my other class called Node. Node has a method called evaluate. I would like walk to override this method like so
My Node class
local Node = {}
Node.__index = Node
function Node.new()
local self = setmetatable({}, Node)
return self
end
function Node:evaluate()
print("Node evaluate")
end
return Node
My Walk class
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Node = require(ReplicatedStorage.Modules.BehaviourTree.Node)
local Walk = {}
Walk.__index = Node
setmetatable(Walk, Node)
function Walk.new()
local self = setmetatable(Node.new(), Walk)
return self
end
function Walk:evaluate()
print("Walk evaluate")
end
return Walk
Outside of this in a local script I am creating a new Behaviour Tree object and passing a Walk object and then calling evaluate on it.
local BehaviourTree = {}
BehaviourTree.__index = BehaviourTree
function BehaviourTree.new(root)
local self = setmetatable({}, BehaviourTree)
self.Root = root
return self
end
function BehaviourTree:tick()
if self.Root then
self.Root:evaluate() -- Prints Node Evaluate instead of Walk
end
end
return BehaviourTree
playerTree = BehaviourTree.new(WalkState.new())
RunService.RenderStepped:Connect(function()
playerTree:tick()
end)
My issue is that the Node’s Evaluate method is being called instead of the Walk’s evaluate. Does anyone know why this is happening?