The PPL Console (by Brad Manske)

A Console Program is a text only interface. It is still a windows program but it eschews the Graphical User Interface (GUI) and event oriented programming for the sake of simplicity. This is just the kind of program you want if your program just processes data and return results. In most cases, when testing the compiler it is quicker and simpler to use the PPL console than to write a Windows GUI program.

To see an example of a console program open the "PPL IDE" link in the PPL program group. Then select "Console..." from the file menu. The PPL console will evaluate what you type on the input line at the bottom and display the results in the output window.

Typing:

10+10

for example, will display 20

It will also work with variables. Try this example:

a$=10
b$=20
a$+b$

The output window will display

> a$=10
10
> b$=20
20
> a$+b$
30

The expressions that PPL can evaluate can be quite complex in this mode and it makes for a handy tool. The real value in the console is using it in your own code. "Hello World" looks like this for a console program:

#include "console.ppl"
func WinMain
InitConsole;
ShowConsole;

write("Hello World");

return (true);
end;

Notice that this is a windows program, so it begins with WinMain. The Console is created and then made visible on the screen. The Write() statement sends the string to the console to be displayed. A Writeln() command also exists that will start a new line after the string has printed. The program ends by returning "true" so that the Console window stays open until the user closes it.

All that remains is to add your code in place of the write statement and you have a way to do unit testing on small pieces of your code. Here are a few string handling operations to get you going:

Write - Send a string to the console
Writeln - Send a string to the console then start a new line
+ - Concatenate 2 strings if alphanumeric ("ab"+"12"="ab12")
+ - add the value of 2 strings if numeric ("10"+"10"="20")
% - Concatenate 2 strings ("ab"+"12"="ab12" or "10"+"10"="1010")
"\n" - advance to the next line on the console

If you want even more control over how the console displays your data, then consult the manual for the "sprintf" statement. C language programmers will recognize this powerful formatting statement. For example:

MyValue$ = 1234;
sprintf(tmpString$, "Value printed in an 8 char field %8d", MyValue$);
write(tmpString$); // " 1234"

If you've followed along so far, you get rewarded with the best tip for using the console, which I have saved for last. ShowMessage() is often used to show the state of the program at some point to help with debugging. But sometimes it doesn't work or you spend all day clicking "OK" because you have to go through a large amount of data before you get to the point in the data where it doesn't work. Instead of dealing with all of that hassle, use the Console.

Create your window, and after the User Interface has been created add InitConsole() & ShowConsole(). Write out the debug statements and before exiting save the console to a file. Now you can search for the case you’re interested in with a text editor.

You should enclose all of the Console calls in #ifdef statements so that they can easily be removed for a production build.

#undefine ProductionBuild // change to #define for no console

#ifndef ProductionBuild
#include "console.ppl"
#endif

func WinProc

// your code - create UI or call the form creation.

#ifndef ProductionBuild
InitConsole;
ShowConsole;
#endif

// your code

#ifndef ProductionBuild
Writeln("Show interesting data in your code.");
#endif

return(true);
end;

That is the quick run down on the console. I've never tried using the Console to log the progress inside a game. I'm hoping that some game designer out there will give this a try. If you do, please tell us all about it in the Forums at http://www.arianesoft.ca/forum.php.