Left 4 Dead 2

Left 4 Dead 2

View Stats:
How can I bind a command with space in it (how to use more than one set of quotation marks)?
I'm tring to change my in-game display name without changing my Steam display name, so I used command like this:

setinfo name "My new name"

This works fine but it's too long to type every time after change the map, so I decided to bind that command to a key, so basically I want something like this:

bind kp_end "setinfo name "My new name" "

But this won't work. I tried to use single quotation marks but they don't work either. I tried to write that like into a .cfg file and bind that key to exec that config file all I get is I set my name to "unnamed". "My new name" is acturally a Chinese character, I guess there's something wrong with encoding - I'm using UTF-8 without BOM I can't see why it won't work.

Anyone, help?
< >
Showing 1-10 of 10 comments
hmm I can't test this out but you could try something like

alias rename setinfo name "my new name"

(you may not need quotes, try it with and without)

And then in your cfg

bind kp_end rename

EDIT:

Oh. Derp! Alternatively, I know for a fact this will work.

Create a new cfg, say, "GiveMeACoolName.cfg". Make the contents of this cfg,

setinfo name "My new name"

And now, bind kp_end exec GiveMeACoolName
Last edited by scintillating luminescence; Feb 23, 2015 @ 10:06am
Erica Hartmann Feb 24, 2015 @ 7:51pm 
Originally posted by scintillating luminescence:
EDIT:

Oh. Derp! Alternatively, I know for a fact this will work.

Create a new cfg, say, "GiveMeACoolName.cfg". Make the contents of this cfg,

setinfo name "My new name"

And now, bind kp_end exec GiveMeACoolName

But I need to use non-English characters, for example:

setinfo name "叒"

If I save this line to a .cfg file and exec it in-game, I'll get my name changed to "unnamed"

However, if I type this line into console, it would be perfectly fine.

I'm using UTF8(without BOM) for the .cfg file, maybe I should try something else?
Last edited by Erica Hartmann; Feb 24, 2015 @ 7:52pm
whoops I just realized your last paragraph said exactly what I suggested. Can you try making a text file that isn't UTF8? In Notepad in the save dialog change the Encoding to Unicode. Can Sourcemod read that?

Also did you try the alias? the only problem being you need to add the alias every time you launch, if you can't put it in a cfg.

EDIT:

Nope, just tried it, source only understands ANSI (UTF8 without BOM). The BOM screws it up. hmmmm

EDIT2:

Okay, I think I figured it out.

Postulation: the source engine cfg parser only handles 8 bit text files.

Observation: When using 16-bit aka Unicode, and a cfg file with the contents "foo", and I exec thet cfg, I get unknown command "�" (probably the BOM) and then unknown command f. So I changed to UTF8 (WITH BOM!). I still get the "�" BUT! if I put "foo" on the second line, by itself, I get unknown command "foo" after the �. So if you skip the first line, you can skip the BOM, but you still need 8-bit format (so UTF8).

Now, Notepad with UTF8 and BOM allows me to save your 叒. That doesn't necessarily mean it will work in game, though =( The reason being UTF8 is kindof a hack and 叒 will probably be interpreted as multiple 8-bit characters...

The reason I say this is that I tried echo 叒 in console and I got � � � . But you said the name thing works for you. Soooo idk maybe? Give it a shot.
Last edited by scintillating luminescence; Feb 25, 2015 @ 6:07am
Erica Hartmann Feb 28, 2015 @ 11:02pm 
Been away for a while :) I'm not sure if it's ok to reply here but I'm not gonna open a new thread for the very same topic, so here I am.

Originally posted by scintillating luminescence:
The reason I say this is that I tried echo 叒 in console and I got � � � . But you said the name thing works for you. Soooo idk maybe? Give it a shot.

That's the problem. Console won't display the character "叒" correctly unless you put quotation marks around it, like this:


] echo 叒
� � �
] echo "叒"


That's why I can't simply use the command:

bind kp_end "setinfo name 叒"

The problem is, it seems that when console read a .cfg file, all unicode charactors would be ignored. For example, If I write the two commands above into a .cfg file and exec it in-game, I will get nothing but two blank lines.

Is this some kind of BUG?
bear Mar 1, 2015 @ 12:34am 
bind kp_end "say setinfo name "叒""
Did you try UTF8 with BOM and leaving the first line blank?

Also. When all else fails...Auto Hot Key. You could make an auto hot key script that automatically types out the setinfo thing when you press a key. Then it's just "press console, press rename button, escape console" Might even be able to make it open the console for you, too, but you might need a bit of a wait between open console and typing the command.

@Bear, you cannot put quotes inside quotes. AFAIK there's no way to escape quotes in the cfg files either. The exception is to use the alias command.

And even if you could bind it, your binds are stored in config.cfg, so the next time you boot the game, same problem - it will fail to read the correct string out of config.cfg.
Erica Hartmann Mar 1, 2015 @ 3:10am 
Originally posted by scintillating luminescence:
Did you try UTF8 with BOM and leaving the first line blank?

I've tried all the options, UTF-8 with/without BOM, UCS-2 Little Endian (I read on valve developer site saying this is required encoding for locazation files but it doesn't work in this case) Nothing helped.

Originally posted by scintillating luminescence:
Also. When all else fails...Auto Hot Key. You could make an auto hot key script that automatically types out the setinfo thing when you press a key. Then it's just "press console, press rename button, escape console" Might even be able to make it open the console for you, too, but you might need a bit of a wait between open console and typing the command.

Yeah... I use AHK quiet a lot, and I can set my mouse side button to input the long line for me but still, I'm looking for a "native" way to do this - worst case I'll just change my steam name and change it back when I'm done playing.

Originally posted by scintillating luminescence:
And even if you could bind it, your binds are stored in config.cfg, so the next time you boot the game, same problem - it will fail to read the correct string out of config.cfg.

And this is the biggest problem. I think there's nothing left I can do unless valve fix the bug.
hmmmmm

You seem technically competent and eager for a solution. After doing some more research I have the following suggestion.

Have you ever heard of a Resource File? It's a programmer thinger, the file has an extension .rc. Resource files are themselves Unicode in format, which is bomb for our purposes. Notably, Steam\steamapps\common\left 4 dead 2\left4dead2\cfg\valve.rc appears to be executed by the game (actually valve.rc is what execs autoexec.cfg)

Open valve.rc in a Unicode-enabled text editor and see if that might help you with the cfg problem. Since all Resource Files are in Unicode by default this *should* work...

EDIT:

Saddest face ever. I tried it. Didn't work. Calling it an .rc file is a lie - it's actually just another cfg file with a fancy file extension =(

Help me AHK-Kenobi. You're my only hope.
Last edited by scintillating luminescence; Mar 1, 2015 @ 9:31am
Erica Hartmann Mar 2, 2015 @ 8:04pm 
Just post my ahk code here in case someone else need it:

----------
#NoEnv
#SingleInstance force

Numpad1::
{
Send {SC029}
Sleep 100
Clipboard = setinfo name "叕"
Send ^v{enter}{esc}
}
----------

So it sends the ~ key (which opens the console) wait for a while, set the clipboard to desired content, and paste it into console then send enter key to submit and escape key to return to game.

I tried to send the string directly into console using ahk's send {u+XXXX} function, but somehow it fails (it works fine in the notepad but inputs wired things into in-game console. That's why I used clipboard to do the work. I didn't clear the clipboard or restore the content though but it's not hard to do.
Sweet +rep for sharing your final solution, especially since it required that clipboard workaround.

Also, not sure about what noenv and singleinstance do, but one thing that I often do is wrap ifwinactive around my ahk gaming scripts. This way the script only works while the game is the active window, and if the window loses focus, the script won't run. This is especially important if you rebind m2 to +forward for games that won't let you rebind mouse buttons, like Dead Space. You can use AHK's Window Spy utility to see the ahk_class name.

For example, the ahk_class for Left 4 Dead 2 is Valve001 (this is the same for Portal 2 and, I imagine, many other Valve games). So, wrap this around your script.

#ifwinactive ahk_class Valve001

; insert ahk-fu here

#ifwinactive
< >
Showing 1-10 of 10 comments
Per page: 1530 50

Date Posted: Feb 23, 2015 @ 8:30am
Posts: 10