Read (Console) Variables and print them

Read (Console) Variables and print them - Close-up of Eyeglasses

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.




Pictures about "Read (Console) Variables and print them"

Read (Console) Variables and print them - Black Pen on Book
Read (Console) Variables and print them - Crop woman reading text on paper
Read (Console) Variables and print them - Stylish sunglasses placed on opened magazines



How do I print a variable value in console?

log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user. Syntax: console. log(A);

How do I print output from console?

To print a String to console output, you can use System. out. print() or System.

How do I view a variable in console?

Open the console and then enter:
  • keys(window) to see variables.
  • dir(window) to see objects.


  • Which console method can be used to print?

    log is the most commonly used console method. It is used to log the output to the console. We can print any data type using log() , be it a string, array, object, boolean, etc.



    03 How to print variables in the console.log - Javascript Beginner Exercises Tutorial Interactive




    More answers regarding read (Console) Variables and print them

    Answer 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.

    Answer 3

    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.

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Pixabay, Talha Riaz, Ono Kosuki, Wallace Chuck