I’ve seen a lot of people talk about it, both in and outside of Roblox. I know that it is a “type” of scripting/programming that is used for more organization, but what is it? And what are the differences between OOP and “normal” programming?
Please tell me if this post doesn’t fit this category and i will change it
Object Oriented Programming is a type of programming that revolves around “objects”, here is a post: All about Object Oriented Programming - Resources / Community Tutorials - DevForum | Roblox
It explains a lot about OOP. OOP utilizes objects while “normal” programming does not mingle with objects (it technically does, but if you read into the link I sent you, you’ll notice a difference).
in short, its the self variable you see in open source module scripts ( I think )
local Person = {}
Person.__index = Person
function Person.new(name)
local self = setmetatable({}, Person)
self.Name = name
return self
end
function Person:adadadadadad()
print("Hi, my name is " .. self.Name)
end
return Person
local Module = require
local bro = Person.new("saul")
bro:adadadadadad() -- how to use `:` correctly
local HttpService = game:GetService("HttpService")
local Signal = {["Connections"] = {}}
local Connection = {}
Signal.__index = Signal
Connection.__index = Connection
function Signal.New()
local SignalId = HttpService:GenerateGUID(false)
Signal.Connections[SignalId] = {}
return setmetatable({["Id"] = SignalId}, Signal)
end
function Signal:Fire(...: any)
for i, FunctionInfo in ipairs(Signal.Connections[self.Id]) do
FunctionInfo.Function(...)
if table.find(FunctionInfo, "once") then table.remove(Signal.Connections[self.Id], i) end
end
end
function Signal:Connect(Function: any)
if type(Function) == "function" then
local FunctionId = tostring(Function)
table.insert(Signal.Connections[self.Id], {["FunctionId"] = FunctionId, ["Function"] = Function})
return setmetatable({["Id"] = FunctionId, ["ScriptConnection"] = self.Id}, Connection)
end
end
function Signal:Once(Function: any)
if type(Function) == "function" then
local FunctionId = tostring(Function)
table.insert(Signal.Connections[self.Id], {["FunctionId"] = FunctionId, ["Function"] = Function, "once"})
return setmetatable({["Id"] = FunctionId, ["ScriptConnection"] = self.Id}, Connection)
end
end
function Signal:Wait(): any
local Finished, Results = false, nil
local Function = function(NewResults) Finished = true; Results = NewResults end
local FunctionId = tostring(Function)
table.insert(Signal.Connections[self.Id], {["FunctionId"] = FunctionId, ["Function"] = Function, "once"})
repeat task.wait() until Finished
return Results
end
function Connection:Disconnect(): ()
for i, ConnectedConnection in ipairs(Signal.Connections[self.ScriptConnection]) do
if ConnectedConnection.FunctionId == self.Id then
table.remove(Signal.Connections[self.ScriptConnection], i)
end
end
self = nil
end
return Signal