Read (Console) Variables and print them

counter-strike-global-offensive

I'm trying to create a bind for my autoexec.cfg, where I toggle the voice_enable variable

bindtoggle "F1" "voice_enable"

works, and will be translated to

bind "F1" "incrementvar voice_enable 0 1 1"

So, as I said, this works. But I'd like to get some visual feedback (ingame) on the current variable.

The only visual feedback I know would be to say something in chat (maybe there is a better way, if yes, please tell me)

So I'd like to switch the command to something like this

bind "F1" "incrementvar voice_enable 0 1 1; say_team voice: voice_enable"

But as you can imagine, in chat it writes: voice: voice_enable

So my question is, can I read the current value for this variable and print out the variable? So the say command would print something like voice: 1 or voice: 0

Thank you

Best Answer

Well, I personally wouldn't make the command say that in chat, since it could be annoying to other players. You could use "echo" instead, which displays a message in console.

But to answer to your question, I don't have a way you would like it (I doubt that you can even check the variable like that in CSGO), but I have an alternative: Bind it for two keys.

F1 sets voice_enable 1, and you could add a message for that to say it's on.

F2 sets voice_enable 0, and it would give a message that voice is off.

If you use

bind "F1" "toggle voice_enable 0 1"

you can see the change in console, without having to add any "echo" or other commands. Just make sure you have binded console to some key.