Read (Console) Variables and print them

Solution 1:

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.

Solution 2:

There is no way to get the value of a variable within a command — only if you type out the variable by itself. For example, typing say voice_enable in console will print "voice_enable" to chat while typing voice_enable in console will print 1 or 0 to console.

The best alternative here is to manually print voice_enable's value on each toggle while also toggling the variable. Here's how:

bind "F1" toggleVoice;
alias toggleVoice "disableVoice";
alias disableVoice "alias toggleVoice enableVoice; voice_enable 0; say voice: 0";
alias enableVoice "alias toggleVoice disableVoice; voice_enable 1; say voice: 1";

I took this from my answer to another question about a similar problem. It simply creates two aliases that are activated by each other by manually toggling a third alias, and that third alias is then bound to a key to trigger the toggling.

It would be great if a way to dynamically read variable values within commands was added, but it would definitely allow some ridiculous scripts to be created and would therefore have to be banned from official servers.