Skip to content

Instantly share code, notes, and snippets.

@FatsackFails
Last active April 26, 2022 00:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FatsackFails/4ca2b87384468da79f4538255ef3a319 to your computer and use it in GitHub Desktop.
Save FatsackFails/4ca2b87384468da79f4538255ef3a319 to your computer and use it in GitHub Desktop.
Toggle System for Kruiz Control
#Sets toggle01 to off when KC starts up
OnInit
Variable Set toggle01 false
#Send Message to switch toggle01
OnCommand b 0 !toggle
Message Send switchToggle
#Switches toggle01 on and off
OnMessage switchToggle
Variable Load toggle01
Function "var toggle = {toggle01};toggle = !toggle;return {result: toggle};"
Variable Set toggle01 {result}
#Checks to see if toggle01 is on or off
OnCommand b 0 !checktoggle
Variable Load toggle01
If 2 {toggle01} = false
Chat Send "This toggle is off!"
exit
Chat Send "This toggle is on!"
@FatsackFails
Copy link
Author

Description: basic framework of toggle system to switch between two states with the same command or event. On/Off, Red Mode/Blue Mode, etc.
KC Version: v1.3.4
Usage: !toggle to switch back and forth between two states
Usage !checktoggle to check which state toggle is currently in

@FatsackFails
Copy link
Author

For a more in depth look at this code snippet, check out the post on my website.

@FatsackFails
Copy link
Author

FatsackFails commented Dec 7, 2021

This uses new Actions brought into v1.5.3

The original still works, this just uses newer built in ways to achieve the same thing.

# Sets toggle01 to off when KC starts up
OnInit
Variable Set toggle01 false

# Send Message to switch toggle01
OnCommand b 0 !toggle
switchToggle

# Switches toggle01 on and off
OnAction switchToggle
Variable Load toggle01
Param Negate toggle01
Variable Set toggle01 {toggle01}
Chat Send "toggle01 set to {toggle01}"

# Checks to see if toggle01 is set to true or false
OnCommand b 0 !checktoggle
Variable Load toggle01
Chat Send "toggle01 set to {toggle01}"

# Tests toggle01 and does a different action depending on if its on or off
OnCommand b 0 !testtoggle
Variable Load toggle01
If 2 {toggle01} = false
Chat Send "Toggle is off!"
Exit
Chat Send "Toggle is on!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment