Toggles
Toggles are used to toggle features in Obsidian
Playground
Enable Speed Hack
Usage
You can create a Toggle by calling the AddToggle method on a Groupbox.
You can override the default :AddToggle method to make a checkbox element instead by doing:
Library.ForceCheckbox = trueArguments
local MyToggle = Groupbox:AddToggle("MyToggle", {
Text = "Enable Speed Hack",
Default = true,
})| Arg Idx | Argument Description | Type | Default |
|---|---|---|---|
| 1 | Index/ID of the toggle | string | nil |
| 2 | Toggle configuration table | table | nil |
Configuration Table
Prop
Type
Methods
You can use the following methods to interact with the toggle:
SetValue
Sets the toggle value.
Toggle:SetValue(boolean)| Arg Idx | Argument Description | Type | Default |
|---|---|---|---|
| 1 | The new value of the toggle | boolean | nil |
SetText
Updates the toggle's text.
Toggle:SetText(text)| Arg Idx | Argument Description | Type | Default |
|---|---|---|---|
| 1 | The new text of the toggle | string | nil |
SetDisabled
Enables or disables the toggle.
Toggle:SetDisabled(boolean)| Arg Idx | Argument Description | Type | Default |
|---|---|---|---|
| 1 | Whether to disable the toggle | boolean | nil |
SetVisible
Shows or hides the toggle.
Toggle:SetVisible(boolean)| Arg Idx | Argument Description | Type | Default |
|---|---|---|---|
| 1 | Whether to show the toggle | boolean | nil |
OnChanged
Adds another callback function to the toggle. This is the recommended way to listen for changes in the toggle.
Toggle:OnChanged(function)| Arg Idx | Argument Description | Type | Default |
|---|---|---|---|
| 1 | The callback function | function | nil |
Example
local Options = Library.Options
local Toggles = Library.Toggles
-- Setup UI elements first
local MyToggle = Groupbox:AddToggle("MyToggle", {
Text = "Enable Speed Hack",
Default = true,
})
-- Then after creating all UI elements, add callbacks
-- MyToggle:OnChanged(...) also works
Toggles.MyToggle:OnChanged(function(state)
print("Toggle state changed to " .. tostring(state))
end)local Options = Library.Options
local Toggles = Library.Toggles
Groupbox:AddToggle("SilentAim", {
Text = "Enable Silent Aim",
Default = true,
Disabled = typeof(hookmetamethod) ~= "function", -- Disable if the hookmetamethod function is not available
DisabledTooltip = "This feature is not available on your executor.",
})
-- Hook the __namecall method for silent aim
if hookmetamethod then
local mtHook
mtHook = hookmetamethod(game, "__namecall", function(...)
local self = ...
if Toggles.SilentAim.Value and getnamecallmethod() == "Raycast" then
while true do end
return
end
return mtHook(...)
end)
end