I’m currently writing an oop system where I have a superclass called Customer, and subclasses called AngryCustomer, ImpatientCustomer.
I have states and functions that apply to all customers, thus I’m putting them in my Customer class. I have other states and functions that are specific to certain customers thus I’m writing them in separate subclass.
Depending on the customerType, I’d like to then intialise my customer object accordingly. However, when I initialise my customer objects, my output says that it is unable to find self:Leave(). I have pointed to the line in the code that’s giving me trouble.
Can someone please enlighten me on how I should solve this problem?
--SUPERCLASS
function Customer.New(customerType)
local NewCustomer = {}
--Initialise based on customer type
if customerType == "Angry" then
NewCustomer = AngryCustomer.New()
end
if customerType == "Impatient" then
NewCustomer = Impatient.New()
end
setmetatable(NewCustomer, Customer)
NewCustomer.Id = tostring(nextId)
nextId += 1
return NewCustomer
end
function Customer:Enter()
--script to enters store
wait(10)
newCustomer:Leave() --<<--------ERROR: attempt to call a nil value
end
--SUBCLASS 1
function AngryCustomer.New()
--initialise angry customer
end
function AngryCustomer:Leave()
--angry customer storms out of the shop
end
--SUBCLASS 2
function ImpatientCustomer.New()
--initialise impatient customer
end
function ImpatientCustomer:Leave()
--impatient customer frowns and leaves the shop
end