Created
August 19, 2023 16:46
-
-
Save Accoast/bbb6360422c0908cfcb5dd20568d71af to your computer and use it in GitHub Desktop.
Luau --!strict Typechecking OOP Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --!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