Hi! I’m currently learning about OOP, and I made these modules by myself. I wanted to ask if I wrote this in good practice, or if there are better ways of doing this. The code is working, when I call Light.new(object) in a script, it adds a Proximity Prompt to that part, which when triggered makes the part’s material neon.
I tried to go for a composition style rather than inheritance, thinking that a light has a proximity prompt. Don’t know if it was the best approach though.
What other things could I try to write using OOP to practice more?
Proximity module:
local Proximity = {}
Proximity.__index = Proximity
function Proximity.new(holdDuration)
local self = setmetatable({}, Proximity)
self.HoldDuration = holdDuration
self.ActionText = "Activate me!"
return self
end
function Proximity.Activate(object, changes, player)
for i, change in changes do
print(i,change)
object[i] = change
end
print(player.Name .. " triggered " .. object.Name .. " proximity prompt ")
end
return Proximity
Light module:
local Proximity = require(script.Parent.Proximity)
local Light = {}
Light.__indes = Light
local changes = {
Material = Enum.Material.Neon,
}
function Light.new(object)
local self = setmetatable({}, Light)
self.Prompt = Proximity.new(1)
local int = Instance.new("ProximityPrompt")
int.HoldDuration = self.Prompt.HoldDuration
int.ActionText = self.Prompt.ActionText
int.Parent = object
int.Triggered:Connect(function(player)
Proximity.Activate(object, changes, player)
end)
end
return Light