Skip to content

Instantly share code, notes, and snippets.

@Accoast
Created August 19, 2023 16:46
Show Gist options
  • Select an option

  • Save Accoast/bbb6360422c0908cfcb5dd20568d71af to your computer and use it in GitHub Desktop.

Select an option

Save Accoast/bbb6360422c0908cfcb5dd20568d71af to your computer and use it in GitHub Desktop.
Luau --!strict Typechecking OOP Example
--!strict
local Tool = {}
Tool.__index = Tool
export type ToolSettings = {
debounce : number?,
activatedFunction : (...any) -> ()
}
type Properties = {
activated: boolean,
owner: Player,
toolSettings : ToolSettings,
}
function Tool.new(owner: Player, toolSettings : ToolSettings)
local properties: Properties = {
activated = false,
owner = owner,
toolSettings = toolSettings,
}
return setmetatable(properties, Tool)
end
function Tool.activate(self: Tool)
if self.activated == true then
return
end
self.activated = true
if self.toolSettings.debounce then
task.delay(self.toolSettings.debounce, function()
self.activated = false
end)
end
end
export type Tool = typeof(Tool.new(...))
return Tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment