1

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

3 Answers 3

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.

1

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.

0

OK, you could do it another way:

alias "enable_voice" "voice_disabled"

alias "voice_enabled" "voice_enable 1; say_team "voice: voice_enable 1";alias "enable_voice" "voice_disabled" " alias "voice_disabled" "voice_enable 0; say_team "voice: voice_enable 0"; alias "enable_voice" "voice_enabled" "

bind "F1" "enable_voice"

The key is now bound to an alias that points to another alias(voice_disabled) that will disable the voice and say to the team "voice: voice_enable 0". Then the voice_disabled alias will make the original bound alias point to another alias(voice_enabled) that will enable the voice and say to the team "voice: voice_enable 1". Then it will make the bound alias point to the voice_disabled alias. This should work. If you rename the aliases, be careful you don´t name any alias enable_voice, cause that´s the name of the integrated command and shoulnd´t be overwritten.

1
  • It´s a bit more work and works only with only two possibilities, but the cs:go console is - unfortunately - not so far that you can take values to variables and use them for another command. May 23, 2015 at 10:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .