Toggle that beeps when on/off

Post your working scripts, libraries and tools
GreatGazoo
Posts: 69
Joined: 28 Dec 2017, 02:53

Toggle that beeps when on/off

28 Jan 2018, 02:56

i noticed lot of people like to toggle things on and off, so i made this script today that toggles and beeps

probably been done a hundred times before if so just delete plz

Code: Select all

banana:=0

!y:: ;---------------------------------------alt + y
banana:=!banana
	if (banana=1)
	{
		SoundBeep, 1000, 200
		msgbox, its off
	}
	else if (banana=0)
	{
		SoundBeep, 2000, 500
		msgbox, its on again
	}
		return
User avatar
Delta Pythagorean
Posts: 464
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: Toggle that beeps when on/off

28 Jan 2018, 07:49

If you want to make this script shorter, do this:

Code: Select all

Toggle := False

;====================================
; Alt + Y
;====================================
!y::
;====================================
	Toggle := !Toggle
	SoundBeep(Toggle ? 1000 : 2000, Toggle ? 200 : 500)
	MsgBox, % Toggle ? "its on again" : "its off"
	; MsgBox(Toggle := !Toggle ? "its on again" : "its off") ; V2
	Return

; Remove this function if in V2
SoundBeep(A, B) {
	SoundBeep, % A, % B
}
Short and sweet version. This allows for single line ifs, which work like this (In a nutshell):

Code: Select all

; Long ways.
If Var = Value
	A.Function()
Else
	B.Function()

; Single line.
Random_Unneeded_Function(Var = Value ? A.Function() : B.Function())
The question mark ? is the IF, and the colon : is the ELSE.
Short, easy, simple.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 39 guests