From what I just read it sounds to me like you have not done any programming or worked with compilers before. Am I correct?

Nothing to be ashamed of, but it helps to know this so we actually know what to teach you.

For the benefit of being constructive; I'll assume that you are going to give me a 'yes'...

I'll give you the basic program structure and some things to start you out, BUT --and heed this!-- you are going to have to do a fair bit of reading on your own. Get books, download books on (Object) Pascal from a store, library, online whatever. There is no way at all you are going to grasp how to make programs, let along games, unless you study the art of computer science... programming. It's not hard to learn, but it's also not like learning how to use Photoshop where you just point and click, as you can imagine.


You need to understand that you are not even at pong yet, you're at 'Hello World!'. I'm not going to tell you how long it will take you to get to pong-level stuff, thats entirely up to you, but without the knowledge of basic programming, your really just going to be poking around in the dark not knowing what you are doing and pretty much next to useless if you want to do something constructive. You can't skip his part, boring or not it's what making games is made of. If you didn't already, now you know. :lol:


Skipping the usual highschool Computer Science 'introduction to' crap, every Pascal program compiled by a pascal compiler follows this core structure:

[pascal]program ProgramName;

// uses, var, const, type and function declarations....

begin

end.[/pascal]

This is as simple as a Pascal program can get...

:arrow: After 'program' goes the name of the program. You can use any alpha-numeric characters and the underscore, but NO spaces. However, just like all variable, type, constant and function names it cannot start with a numeric character! This is the first thing the compiler looks for so it must always be at the top on the first line.

:arrow: In-between begin and end. goes the main block of code. This is where your program starts after it has initialized. Included units can have their own code blocks, but this where the main part of the program goes. I'll explain more about what a unit is later.... don't worry about them for now.

:arrow: Above the main code block you'll notice that I have put in a comment. Comments are segments of code that are there for the programmers only. It helps them to better understand are either contained within the { and } characters or follow // on the same line.

Some Object Pascal compilers also have the (* and *) brackets. These are kind of like super comments in that everything including the { and } comment brackets are ignored. I'd stay away from using these for now though. At least until you get your Pascal-legs first. You'll appreciate the difference in their usage then.

You will generally want to declare your program's variables at the top of your program, but anywhere above the main code block and below the Program declaration line. This is indicated by my single line comment above.


Here is a really basic example of how to print text to the screen...

[pascal]program HelloWorld;

begin
writeln('Hello world!');
end.[/pascal]

There she is... that is the infamous Hello World program. All it does is print out a single line of text that says...

Hello world!
If you took this program and an it though a compiler to see for yourself, you probably have a confused look on your face. Yes, the program appears to close right on exit. You might not even see the console window draw anything it would be rather fast, even for a 'slow' computer. This wasn't a problem back in the DOS days, but all this program does is draw a line of text. It doesn't wait, because there is nothing to tell it to.

We can do this by adding another line to tell the program to wait for some user input. Here is Hello World revised...

[pascal]program HelloWorld;

begin
writeln('Hello world!');
readln();
end.[/pascal]

Now the program will wait until you have entered in a line of text and pressed the enter key.


That is the basic program structure and how to write a simple program. What I recommend from this point is that you learn how to do some reading up to learn a few needed things. I have made up a check-list to help guide you. After you have learned all of these key things and how to code them, you should be able to start making more complex programs. Don't skip any of these as you will DEFINITELY want to know this stuff if you are going to make games.


I recommend tackling these in this order...


How to Program Checklist:

:arrow: Declare a variable and set data types.

:arrow: Assign a value to a variable and do calculations.

:arrow: Check for conditions with if ... then and else.

:arrow: Check for conditions with a case statement.

:arrow: Create and use constants.

:arrow: Repeat code with while loops.

:arrow: Repeat code with for loops.

:arrow: Repeat code with repeat loops.

:arrow: Declare an Array and assign values

:arrow: Work with strings and how to convert a Real or Integer value into a String value.

:arrow: Declare your own commands with procedure.

:arrow: Declare your own commands with function and learn how it returns a value.

:arrow: Creating and using records.

:arrow: Creating and using sets.

:arrow: Write your own unit.

:arrow: Read and write to and from Text files.

:arrow: Read and write to and from Binary files.

At this point you should be in a good place with the language and able to move onto more graphical programs, learn other 3rd party units or (libraries as they are more commonly called)...


Once you have a grasp on these and have made a few things that you have successfully compiled and ran tested. Made mistakes with and found your error and fixed them a few times, you will be able to move onto the more 'powerful' parts of the Pascal language...

Here is a pretty good beginner's tutorial to get started: The Basic of Pascal

There are some things that are Turbo/Borland Pascal 7 era, luckily Free Pascal is fairly compatible with most of those things.

If you want to make a new program for learning while using Lazarus, just choose 'Project - Custom Program' in the New... dialog window.