The Command Line Function

Blitz3D Forums/Blitz3D Programming/The Command Line Function

RiverRatt(Posted 2006) [#1]
Hey All:
What does the commandline function in the blitz3d editor do? Can it be used to link documents or applications to the blitz editor?

Thanks


Picklesworth(Posted 2006) [#2]
CommandLine specifies a command line to pass to an application.

Command lines are a common way used in most operating systems to pass values to an application when they launch.

They are set by simply adding a string after a file path.
Eg:
Starting a program with:
"C:\Program.exe" -debug
Would tell it to run in Debug mode. Of course, there are other very imaginative ways to do this... for example, the Grasshopper Web Plugin system (in my sig) passes applications a command line containing arguments sent by an HTML document and an important window handle.


To get command lines in your own app:
appArg$=CommandLine()
Print "Below is this application's command line:"
Print appArg$

WaitKey
End

Just set the command line in the command to boot a program or (for testing purposes -- command line values are not saved within the final executable) via the IDE, and the program will print it.



Some other examples of command lines:
When we view a file in Windows, the application being used is usually launched with a command line containing a path to the file in question.
Screen savers use command lines -- "\S" tells it to run in Screensaver mode, "\P" tells it to run in Preview mode, and "\C" tells it to run in Configuration mode.
Command lines are obvious in text-based OS interfaces. For example, if you open the Windows Command Prompt, changing directories involves executing a program with the new directory as a command line. As does deleting files. The Poweroff program in some places accepts command line values to decide how exactly to power off.
Even the Blitz compiler takes command line values!



Hope this helps!


RiverRatt(Posted 2006) [#3]
I'm sorry, I still don't get it. Why would you use the Comand line? Or why would you need to specify a command line to pass to an application?
In your example above, it returns debug as a variable but I don't see anything else happening. If debug mode is un-checked the program still runs in normal mode. So whats the difference between this and readfile?
Do you have any acual working examples I could look at?
That would help a bunch.

Thanks Mr.Picklesworth


t3K|Mac(Posted 2006) [#4]
e.g. your game has a dedicated server mode. imagine to start your game without command line - your game will run in client mode. start it with -"server" the game starts in dedicated mode without all the fancy graphics stuff for multiplayer. you can test this behavior in the editor directly (you do not have to manually compile, edit the icon of the exe and double click for testing)


Matty(Posted 2006) [#5]

;in your main loop you might have something like this:

if instr(lower(commandline$()),"show fps",1)>0 then text 0,0,"FPS:"+fps





Sir Gak(Posted 2006) [#6]
Sometimes ya jus' gotta do it 8>)


Andy(Posted 2006) [#7]
>What does the commandline function in the blitz3d editor
>do?

It enables you to test your program, if your program uses commandline arguments.

>Can it be used to link documents or applications to the
>blitz editor?

No.

>Why would you use the Comand line? Or why would you need
>to specify a command line to pass to an application?

You use commandline arguments to specifiy options which may be unnessesary for the average user or are very specific in nature.

For example, you could use commandline arguments to test a users system and record errors. game.exe would run your program as normal, but game.exe -debug would create an error log and log every action until the game crashes. This would enable you the developer to figure out what the problem might be.

>In your example above, it returns debug as a variable but
>I don't see anything else happening. If debug mode is un-
>checked the program still runs in normal mode. So whats
>the difference between this and readfile?

Readfile requires that the program either automatically reads an external file, or is prompted by a user to do so. That is not always desirable.

>Do you have any acual working examples I could look at?
>That would help a bunch.

Any game will incorporate some attempt at detecting problems. Let's say that your program uses a fancy algorith, which is based on a slower and less secure algorithm which you used in previous versions of the program.

naturally you would like to ensure that the user aways uses the new algorithm, but just incase there may be problems which you havent found while testing, you leave the old algorithm in the program and enable it to be turned on using a commandline argument.

So you start selling the new version and after a few days you receive an email reporting unexpected results using the new algorithm.

You then tell the customer to run the program with the args 'oldalgo'. He replies that this corrected the problem.

Now you know that there is a problem with the new version of the algorithm, so you need to know where in the program the problem is. You tell the customer to run the program with the arg 'dump', which will write the contents of every variable and type to file as they change, and then send it to you via email.

The customer does so and you are able to find and fix the problem.

In the above example you had had to args 'oldalgo' which made the program use your older algorithm and 'dump' which dumped the variables to file. This is a very simple explanation, but you should be able to see why args are useful.


Andy