Batch File Compiling for Beginners
by Tracer Bullet (view all articles)

unrated
Creation and use of batch files for HL compiling
by Tracer Bullet (view all articles)

unrated

Many times in the forums you will hear someone say ?don?t compile with Hammer@#$!!!!?. Now to a beginner that may not make a lot of sense as I get the feeling that many people do not seem to understand that it is the compile tools (hlcsg, hlbsp, hlvis/netvis, hlrad) that do all the work. Hammer is simply a user interface that attempts to make compiling more user-friendly.
There are any number of different user interfaces for compiling half life maps. Besides being done through Hammer, it cam be done through a third party GUI such as HLCC (graphical user interface), a DOS window, or a batch file. In every case you end up with the same finished product. Whatever interface you use the tools of your choice (ZHLT/MHLT/XPHLT) are run in the same order with a variety of command switches to customize the end result to your needs ( e.g. ?wadinclude, -bounce? etc.- see your tools documentation.htm file for more info).
So if they all do the same thing why is one way better than another? The answer is resources and neatness. In order to run Hammer/HLCC/ZHLT-GUI, your computer has to allocate memory for the interface that could be better spent speeding up the compile. Compiling in Hammer is particularly bad because it not only uses up a lot of RAM, it also locks up the editor. Compiling from a DOS window is very resource efficient, and it?s nice to have direct access to the tools because there is no chance of errors being caused by the vagaries of a GUI. However, you have to call each tool individually which is very annoying and not overly practical if you?re in the habit of doing overnight compiles. Meet the batch file.
A batch file is a series of DOS commands that are executed in sequence. If you are scared of command prompt don?t run! We are going to build a batch file that makes compiling as easing as dragging and dropping you?re mapname.map file. You should also note that Windows XP can still do this as it has its own DOS prompt (of sorts).
The first thing you have to do is create a new plain text document. I called mine compile.bat; .BAT files are the standard for small, DOS applications. Now open it up in notepad or your favourite text editor.
In the below image, you will see my batch file. There are numbers associated with each command. The text below the image explains each command and references its number in the sequence.
Now, to use the batch file you can do one of two things:
Notes:
All paths and file names must be WITHOUT SPACES. Folders should ideally be in DOS format, where you take the first 6 letters of it (ignoring spaces) and add ~1 at the end- type 'dir' at the command prompt to see what you should use.
The location of your batch file does not matter, although it might be a good idea to give it its own separate directory.
To change compile options or tools, just edit the batch file. You might consider having several different files such as, LeakCheck.bat, FastCompile.bat, NormalCompile.bat, and FinalCompile.bat each with your favorite tools and command switches for its purpose. And without any 'programming' knowledge here, you can define a single compile parameter by copying step 3 (e.g. SET rad_options = %2)
This method of compiling can be used to easily transport the compile process to a different computer, such as maybe the uber fast ones at school.... Just remember that you will need all of the textures, and if the path to those textures is different from what it was in your Hammer config you will need to edit the .map file (text format) accordingly.
There are any number of different user interfaces for compiling half life maps. Besides being done through Hammer, it cam be done through a third party GUI such as HLCC (graphical user interface), a DOS window, or a batch file. In every case you end up with the same finished product. Whatever interface you use the tools of your choice (ZHLT/MHLT/XPHLT) are run in the same order with a variety of command switches to customize the end result to your needs ( e.g. ?wadinclude, -bounce? etc.- see your tools documentation.htm file for more info).
So if they all do the same thing why is one way better than another? The answer is resources and neatness. In order to run Hammer/HLCC/ZHLT-GUI, your computer has to allocate memory for the interface that could be better spent speeding up the compile. Compiling in Hammer is particularly bad because it not only uses up a lot of RAM, it also locks up the editor. Compiling from a DOS window is very resource efficient, and it?s nice to have direct access to the tools because there is no chance of errors being caused by the vagaries of a GUI. However, you have to call each tool individually which is very annoying and not overly practical if you?re in the habit of doing overnight compiles. Meet the batch file.
A batch file is a series of DOS commands that are executed in sequence. If you are scared of command prompt don?t run! We are going to build a batch file that makes compiling as easing as dragging and dropping you?re mapname.map file. You should also note that Windows XP can still do this as it has its own DOS prompt (of sorts).
The first thing you have to do is create a new plain text document. I called mine compile.bat; .BAT files are the standard for small, DOS applications. Now open it up in notepad or your favourite text editor.
In the below image, you will see my batch file. There are numbers associated with each command. The text below the image explains each command and references its number in the sequence.

- The double colons (:
before the number designate the line as a comment. It is therefore skipped in the execution of the file.
- The ?echo off? command is an instruction telling the computer not to print commands to the screen. The ?@? symbol is necessary to tell computer that the ?echo off? command is effective at this line. Otherwise ?echo off? would itself be displayed.
- This command is the key to the convenience of the batch file. Batch files can take an argument, which can be a file or a variable. In our case the argument is the mapname.map file. ?%1? always refers to this first argument in a batch file, but to make things clearer I am assigning the first argument (%1) the name ?mapfile?.
- This command sets the root directory for your *.wad files. This is not a necessary command; it simply specifies a default directory for your textures. Obviously, choose whatever directory is best for you or omit this step entirely.
- Call HLCSG with a couple of command switches of your choice:
Now we are ready to start calling the tools you want to use. I?m using the 15th build of XP-Cagey?s tools. The file path points to that particular version of HLCSG. Obveously, you should fill in the correct path to whatever tools you are using. All the tools take the mapname.map file as an argument, and various command switches after that. An example of the typical calling sequences would be ?hlcsg.exe mapname.map ?comand_switch?.
However, what if I want to compile a different map? Using the above calling sequence I?d have to go into the batch file and change the map name and path every time! Do not despair. We already have the solution to this problem in the batch file argument (see step 3).
Because I have designated the first argument to the batch file as ?mapfile? and we know that we will be giving the map to be compiled as the first argument of the batch file, all maps we might want to compile can now be referred to as ?mapfile?. A schematic diagram of this trick is shown below.
The ?%? symbols are required before and after the word ?mapfile? to let the system know that ?mapfile? as a user defined label.
- Calls HLBSP as with HLCSG
- ?VIS
- ?RAD
- Prints ?Completed?? to the screen.
- Stops the DOS window form closing immediately upon completion.
Now, to use the batch file you can do one of two things:
- Go into DOS command prompt and type batchfilename.bat mapname.map and the whole compile sequence set forth in the batch file will run, assuming all your directories are correct and that your map is in the same folder as the compilers! (If it is not, and supposing you keep all your maps in the same directory, it might be worth adding the path to that directory in the batch file to compile and copy commands)
- Drag and drop your mapname.map file onto the batch file!
Notes:
All paths and file names must be WITHOUT SPACES. Folders should ideally be in DOS format, where you take the first 6 letters of it (ignoring spaces) and add ~1 at the end- type 'dir' at the command prompt to see what you should use.
The location of your batch file does not matter, although it might be a good idea to give it its own separate directory.
To change compile options or tools, just edit the batch file. You might consider having several different files such as, LeakCheck.bat, FastCompile.bat, NormalCompile.bat, and FinalCompile.bat each with your favorite tools and command switches for its purpose. And without any 'programming' knowledge here, you can define a single compile parameter by copying step 3 (e.g. SET rad_options = %2)
This method of compiling can be used to easily transport the compile process to a different computer, such as maybe the uber fast ones at school.... Just remember that you will need all of the textures, and if the path to those textures is different from what it was in your Hammer config you will need to edit the .map file (text format) accordingly.