How can I make a custom keybinding to toggle a bool cvar?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
aJynks
Posts: 30
Joined: Fri Aug 30, 2024 6:19 pm

How can I make a custom keybinding to toggle a bool cvar?

Post by aJynks »

I have made a small UI mod.... in that mod there is a custom menu items where I can set an element of that UI to be on or off...

CVARINFO

Code: Select all

nosave bool cVarName = true;
MENUDEF

Code: Select all

Option "Text Label in Option Menu : ", "cVarName", "OnOff"
This all works as expected.. I have a menu option I can click to "on" or "off" and it changes the cvar to true or false and so the code can display the ui element or not....

I would like to make a hotkey do I can display or hide this element on a keypress... but can not work out how. I have tried a bunch of stuff, and will post if people want, I just don't want to put a mass of "not working" stuff here and confuse the post. (KEYINFO, event, aliais, etc etc... just can't get it to work)

: TL;DR :
How do I make a custom key to toggle a cvar bool?

thanks
aJynks
Posts: 30
Joined: Fri Aug 30, 2024 6:19 pm

Re: How can I make a custom keybinding to toggle a bool cvar?

Post by aJynks »

I have this worked out.. Jay on discord was able to walk me through it.. I was pretty close on my attempts but just didn't know about something called "toggle" lol...


High Rez Version of Chat

Basically... all I needed to do was this (for my case)

KEYCONF

Code: Select all

alias myCommandName "toggle cvarName"
MENUDEF

Code: Select all

Control "Option Name :  ", "myCommandName"

Return to “Scripting”