I recently picked up Object-Oriented Programming in ROBLOX. I have a few years of experience in coding with OOP languages (C#, Java, JavaScript etc.) but I never encountered this problem I have currently with Lua.
So long story short here’s my Person class:
local Person = {}
Person.__index = Person
function Person.new(name, age,gender)
local self = setmetatable({}, Person)
self.name = name
self.age = age
self.gender = gender
return self
end
function Person:PrintPerson()
print("Name:", self.name)
print("Age:", self.age)
print("Gender:", self.gender)
end
return Person
And the script that tests the module:
local PersonClass = require(game.ReplicatedStorage.Person)
local Gender = require(game.ReplicatedStorage.Gender)
local name = "Jefferson"
local age = 15
local gender = Gender.Male
local person = PersonClass.new(name,age,gender)
person:PrintPerson()
Now the issue is that when I try to call the PrintFunction() from the Module Script ROBLOX recommends me the : functions even through I’m using the .
The sad truth is no, there is no way to hide those.
I myself had many users constantly misuse my OOP modules because of this feature.
The only way to help users is to write a detailed read of how to use the module.
I guess such a dynamic low level language comes at a cost then. Being careful when using the module functions and proper documentation is the solution.
Thanks a lot!
I guess the only way you could possibly fix this is by detecting if self doesn’t exist and applying a custom warning/error to notify the user about using colon functions instead.