Escaping double quotes in TF2 scripting

908 Views Asked by At

In TF2 scripting, there is a simple command, echo. This simply logs a message to the console. It can be used with or without double quotes. However, I want to be able to log something to the console involving double quotes--say, the string He said, "nope.". In conventional programming, one would escape the quotes, as so:

echo "He said, \"nope.\""

However, in the TF2 console, this writes:

He said, \ nope.\ 

Is there a way to use quotes in echo and related commands? (E.g. say)

2

There are 2 best solutions below

2
On BEST ANSWER

It's not possible to output double quotes using echo or say, only single quotes. (source) (In fact whenever you type double quotes into regular chat they're automatically changed into single quotes. I don't know why this limitation exists, I'd have to dig around.)

0
On

I know this is a very old thread, but in case anyone else is trying to find a fix for this and found this post, let me provide an example of how to use single quotes. I had an alias for switching crosshairs, as such:

alias "default" "cl_crosshair_blue 255; cl_crosshair_red 255; cl_crosshair_green 0; cl_crosshair_file "" "

This is to change the color of my crosshair, but more importantly, reset my crosshair to the "None" in options, letting the crosshair change depending on weapon, as I like most of the default crosshairs- but it would fail at the quotation mark immediately after "file", simply changing the colors and nothing more.

Using single quotes fixes this. Using ALT+0145 and ALT+0146 gives you the starting and ending single quotes (respectively) that you need. Replacing those two double quotes after "file" with the single quotes made the command work as intended.

alias "default" "cl_crosshair_blue 255; cl_crosshair_red 255; cl_crosshair_green 0; cl_crosshair_file ‘’ "

So anytime you absolutely need to use a set quotation marks twice in a command, just use single quotes.