Thursday, 5 April 2012

Standard Template Code

Every new project starts the same way, with the example code shown in the last post, so its a good idea to do a quick run through what it does.  Ease in gently so to speak.

The rem command at the start of a line indicates that the line is a remark, simply a way to leave notes in the code to explain to the future you what that code does.  Remark lines are shown in the editor in green.

There are a couple of other ways to indicate remarks, using two forward slashes (//) or a single quote character (`) - be careful with this as it's not the one used as an apostrophe ('), the line colour will let you know if you have the right one.
Well that's five lines out of the way.

SetDisplayAspect( 0.66 ) is used to set the aspect ratio of the screen for portrait applications.  If a landscape project had been started, this would have been SetDisplayAspect( 4.0/3.0 )

By default, AGK uses percentages for the on screen position of graphics;
  • The left edge is 0 and the right edge is 100 along the X axis
  • The top is 0 and the bottom 100 down the Y axis.
Since a typical screen is not square, the SetDisplayAspect() command is used to tell AGK how not square it is, so that graphics can be adjusted accordingly to show in the right proportion.

This project won't be using the percentage coordinate system so the command won't be around for too long.

The do and loop commands are used as a pair to indicate an infinite loop.  When the program reaches the loop command it goes back to the corresponding do command.   Used here it defines the main program loop which is repeated without end.

For clarity, its good practice to indent code within loops so the start and end of a loop is obvious at a glance.  Here one the code within is indented by one character, most people would probably use a more obvious tabbed indent.

The Print("hello world") command does simply that, it prints the hello world onto the screen.

The Sync() command does a number of things, the short version is that it pauses the program until the display is ready for an update, then it updates the display.

And that's a quick overview of the standard code.

No comments:

Post a Comment