So for the funs i decided to try to make a game framework module to practise my OOP skills. I started out with a simple module. Basically all i have atm is just a method in my module called “RunFunc()” which you can bind stuff to. Such as a schedule n stuff.
All i want to know is if my module is efficient enough or if theres anything that can be improved/changed??
How it looks like inside a normal script. Two examples. Also the arg after the functions on “RunFunc” are the ids for the task/schedule(Atm the ids doesnt really do that much):
local Framework = require(script.Parent.Framework)
local A = Framework:RunFunc(function()
print("Schedule 1")
end,1):ScheduleFunc(5)
local B = Framework:RunFunc(function()
print("Schedule 2")
end,2):ScheduleFunc(5):WaitAndThen(1):CancelSchedule()
Framework module:
local Framework = {}
local Scheduler = require(script.Scheduler)
function Framework:RunFunc(Func,Id)
if Id then
return Scheduler.new(Func,Id)
else
Func()
end
end
return Framework
Schedule module:
local Scheduler = {}
local FuncsInSchedule = {}
Scheduler.__index = Scheduler
local WaitModule = require(script.Parent.Wait)
-- // Others
local NewThread = task.spawn
-- // End
function Scheduler.new(Handler,Id)
return setmetatable({_Func = Handler,FuncId = Id},Scheduler)
end
function Scheduler:ScheduleFunc(Time: number)
local NewWait = WaitModule.new()
NewThread(function()
NewWait:Wait(Time)
self._Func()
self = nil
end)
return setmetatable({Timer = NewWait},Scheduler)
end
function Scheduler:WaitAndThen(Time)
WaitModule.new():Wait(Time)
return setmetatable({Timer = self.Timer},Scheduler)
end
function Scheduler:CancelSchedule()
self.Timer:CancelWait()
self = nil
end
return Scheduler