Part of my writing on hobby videogame development.
- = Command-Line Arguments and Navigation = -
By Chris DeLeon
What's Covered Here?
I'll aim to answer the following questions:
I'm assuming only casual level of background in computer usage (ability to use Word, iTunes - standard consumer-oriented software).
What is the Command-Line?
The command-Line is a text interface that can be used to accomplish many of the same things that are currently done by drag and drop visual interfaces via Windows, OS X, and Linux GUIs like KDE or Gnome. The most common command-line actions:
Before the invention and adoption of GUIs (Graphical User Interfaces) like Windows/OSX/KDE/Gnome, command-line was the only way for most users to perform even basic tasks on files and folders.
Why Learn Command-Line?
For the majority of computer users, using the command-line is never going to be more efficient than pointing and clicking. That is the better way for most people to complete most tasks.
Programmers have needs that differ from many other users. In addition to manipulating a lot more files than a typical user, programmers frequently need to Start applications with command-line arguments, which is more cumbersome to do through the visual interface than via command-line. In particular, this is how we use compilers for free (this practice is 100%, unquestionably legal).
Compilers are the software that converts a programmer's human readable typed code into machine runnable executable code. Most compilers - for everything from assembly to C to Adobe Flash - can be used for free if handled via command-line rather than via an expensive IDE (Integrated Development Environment) such as Visual Studio or Flash Builder. It is not necessary to spend any money to program.
Those expensive IDEs are essentially just a combination of a text editor (often with language-specific autocomplete and syntax coloration), enforced project organization, and a way to use menus to choose command-line arguments for the otherwise free command-line compiler.
What are Command-Line Arguments?
Command-line arguments are words typed after a program's name on the command line. These words are visible to the program, which can then used as configuration settings for execution.
For compilers in particular, command-line arguments typically specify things like which source code file(s) to compile, what filename and directory is desired for the compiled program, and optional flags to customize how compilation is performed (optimization level, debug information, etc.).
The above line compiles the ActionScript 3 source file "myGame.as", generating "myGame.swf" in the same folder, on a Mac or Linux machine (thus the "./" at the start of the application call). "mxmlc" is the name of the command-line compiler used by Flash. mxmlc is available free from Adobe here for both Mac and Windows - it's buried in the bin folder after unzipping. (Note that you can ignore the questions on that page about backend and purpose. Just click Download Now.)
g++ main.cpp core.cpp -o breakout-mac `allegro-config --libs`
The above compiles the C++ source files" main.cpp" and "core.cpp", generating the program name "breakout-mac". The last part tells the compiler to use the Allegro library. The Allegro library is free and offers a variety of functions for videogame input, graphics, and audio. The gcc / g++ compiler is available for free via MinGW for Windows, for free as part of XCode for Mac, and are installed by default on Linux.
How to Get Around
Generally speaking, calling a program and passing command-line arguments to it will only work if the program is within the folder that is currently in focus.
Let's take a look at how to do these three things through the command-line:
If you know how to (1.) Tell where you are (2.) See where you can go (and 3.) Go where you can see, then you'll know enough to navigate to any folder on your computer with the command-line.
Which section to read next depends on whether you are using cmd.exe in Windows or you are using Terminal on Mac. (The latter also applies to Linux.)