Language Library

Introduction

Programming language

Decisions

Loops

Functions

Library functions

Debug
Options
Tools
Ascii codes
Error messages

Hello World program

There is a tradition in programming that the first program that you write in a new language is the "Hello World" program. This is simply a program that displays the text "hello world".
Select New from the File menu. This starts a new program.

fn Main

endfn
will appear in the program code window.

This is the main function. All programs have a main function. A program may have additional functions after the Main function. All functions start with a line such as
fn AnyThing
and ends with a line
endfn

The Main function does not do anything yet.

A function does not do anything unless it has at least one line in he middle. A function can have any number of lines in the middle.

To make the program do something, add the line
print "Hello world"

Run the program by pressing the function key F5.

"Hello world" will be displayed in the output window (though without the quotation marks).

In the Help window you will see


3 lines executed.
Program ended.
displayed.

You can save your program by selecting Save from the File menu. The default name for your program is noname.ezy. Change this to hello.ezy. The suffix .ezy shows that this file is an Easy C program.

Quit the program by selecting Exit from the File menu.

Restart the program. Select Open from the File menu. A list of .ezy files will be displayed. Select hello.ezy. You will see the program code displayed.

You can test a program by pressing the function key F4. This does not run the program but will list any errors.


EDITING YOUR PROGRAM

You can use the 4 cursor keys and the backspace key to edit your code. You can also use all the actions possible from using the Edit menu such as cut, Copy and Paste etc.

Pressing F2 causes all the lines within blocks of code to be indented. This makes code easier to read. Pressing Shift + F2 does the opposite.

Pressing F2 also causes certain words to change from lower case to titlecase. Titlecase uses a mixture of uppercase and lowercase letters. The first letter in a word is uppercase while the remaining letters are lowercase. If there are several words joined together then the first letter of each word is uppercase.

Pressing the enter key when the cursor is at the end of the line will complete a template. If the keywords fn, if or while are at the start of the line then endfn, endif or wend will be added on a new line.


RUN

F4 tests the program. If there are any errors then they will be displayed.

F5 or the Run menu tests the program. If there are no errors then the program starts. If there are any errors then they will be displayed and the program will not run.

Selecting Debug puts you into Debug mode.

F6 allows you to quit a program if you wish to end it early.


THE PROGRAMMING LANGUAGE

Program Lines

A program is made of statements. A statement is one program line. A statement is like a sentence in English.

When the program runs the statements are executed (the computer performs the instructions) in order.


Comments

You can add comments to your program. Comments are ignored. Any text after an apostrophe is a comment. An apostrophe can be placed at the start of a line or anywhere on a line.

code> fn Main
print "Hello world" ' this is a comment
endfn

If you select open from the file menu you can run one of the sample programs.

Double clicking on a word will display help on it if it is available.


Tokens

Each statement is composed of one or more tokens. Tokens are seperated by spaces or commas.

Tokens can be keywords, literals, operators, variables, function calls, libray function calls etc.


Keywords

A programming language has its own special words called keywords. Keywords are always in lowercase. If a statement includes a keyword then the keyword is always the first word in the statement. Some keywords are always on their own. Other keywords always use other words.

In addition to keywords, you can create your own names. Only certain letters can be used in names. Names must start with a letter. Other characters can be numbers or letters. Names cannot be keywords or names used in the function library.

Names can be used for variables, constants, arrays and functions.

A $ dollar can be placed at the end of a name to indicate its a string. (The $ looks a bit like s, which is the first letter in the word string.)


Literal Strings

A literal string is any text within a pair of double quotes. "Hello world" is a literal string. The quotes are not part of the string, but show where the string starts and ends.

Literal Numerics

A number like 187 is a literal numeric.


Operators

Operators are symbols that can act on variables and literal values. These include the arithmetic operators: The comparison operators: The assignment operators:

Variables

A variable is something that can take on different values. Its value varies.

There are 2 types of variables Number variables, which can hold a positive or negative value. String variables, which hold the value of a literal string.

A variable can be created by using the var keyword.
var x creates a number variable called x.
var a$ creates a string variable called a. The $ is needed to show a is a string variable.

Assigning Values You can give a variable a value by using an equals sign.

x = 1 gives x a value of 1.
a$ = "hello" gives a$ a value of "hello". Note that the = sign can be used in two different ways:


Arithmetic

You can use arithmetic with number variables.

Concatenation

You can join strings together by using the plus symbol.
a$ = "hello" + "world"

The plus symbol is the only mathematical symbol that can be used with strings.


Constants

Constants are very like variables, except that they can never change their value.

Syntax

A keyword can only be the first token in a statement (though the first token could be something else).

The first token can be a keyword, variable (constant), libray sub call.

If the first token is a variable then the second token must be = followed by what it is being assigned. This could be variables, literals for function calls.

The first token cannot be a literal or operator.

Tokens can be keywords, literals, operators, variables, function calls, libray calls etc.

The last token cannot be an operator.


Decisions

A decision means that the program will decide to execute a block of statements if a condition is true.

A condition is either true or false. Conditions are comparisons between two things. Comparison operators are used to compare the left side and the right side.

a = b If a has the same value as b then the condition is true else it is false.

a <> b Is a not equal to b?
a > b Is a greater than b?
a < b Is a less than b?
a >= b Is a greater than or equal to b?
a <= b Is a less than or equal to b?

The left side can be a variable or a function call.

The right side can be a variable or literal or a function call.

A decision always starts with an if statement and ends with an endif statement.


if condition is true
	statements
endif
If the condition is true then the statements will be executed otherwise they will be passed over.

if condition is true statements else statements endif

A decision can include the else keyword. The else keyword can only be used within an if...endif block. When else is used then either the statements before the else are executed or the statements after the else are executed. There will always be some staements in the block executed.

A decision can also include one or more elseif keywords. elseif is followed by a condition, just like an if. Like else, elseif can only used within an if...endif block.

it is possible to use else and elseif in the same if block.


Nesting

Nesting means to place something within something else. If blocks can be nested. indenting lines makes it easier to read nested statements.

if condition 1
	if condition 2
		statements
	endif
endif

Loops

Loops allow the same statements to be repeated. There is one type of loop the
while loop. A while loop always ends with a wend statement. A while loop looks like this:

while condition is true
	statements
wend

If the condition is false to begin with, then the statements in the block will never be executed.

break

break causes the program to jump out of a loop.

while condition is true
	statements
	if condition
		break
	endif
wend

Nesting loops

Loops can be nested within each other.

while condition 1 is true
	while condition 2 is true
		statements
	wend
wend
Loops can also be nested with if blocks.

Functions

return

The
return keyword is used to return a value from a function.

return 6 returns the number 6
return x returns the value of the variable named x
return "abc" returns the string "abc"
return a$ returns the value of the variable named a$


Passing arguments

It is possible to send values to a function. This is called passing arguments.

Arguments can be passed to library functions and user functions (functions created by the programmer.) If more than one argument is passed to a function then they are seperated by commas. Arguments can be literal numbers or strings, variables or functions.

The number of arguments passed to a function must be the same number as what the function is expecting.


Arrays

An array is a group of variables which all have the same name. Arrays can be numbers or strings. Array members have their own index number. Arrays use square brackets to show the index number.

var boxs[100] creates a number array called boxs which has 100 elements.

var month$[12] creates a string array called month which has 12 elements.

boxs[12] = 99 assigns the value of 99 to the number 12 element of the boxs array.

month$[1] = "Jan" assigns the value of "Jan" to the number 1 element of the month$ array.


Library functions

There are many existing library functions that can be used. These can be viewed by selecting Libray in the Help menu.

For example, Print is used to used to print text on the screen.

SetFont can change the current font.


String functions

Functions which have a name ending in a $ are called string functions and return a string. Some library string functions are:

Screens

The screen is made up of individual pixels (short for picture elements). Each pixel has a x (horizontal) co-ordinate and a y (vertical) co-ordinate.

The x co-ordinate of the left hand side is 0 and increases to the right. The y co-ordinate of the top is 0 an increases to the bottom.

The co-ordinates are important for drawing on the screen.


Graphics

Individual pixels (the dots that form the screen) can be filled in with PSet (short for pixel set).

Line can be used to draw lines.

Circle can be used to draw circles.

Ellipse can be done to draw ellipses.

Rect can be use to draw rectangles (which may be filled or empty).

Polygon and PolyFill can be used to draw polygons. Polygons can have up to 10 x and 10 y co-ordinates.

Paint can be used to start filling the screen with a certain colour. The colour will continue until the border colour is reached.

Point can be used to see what the colour of a pixel is.

Colours can be set by using prefined values. These are:

Colours can created by using the rgb function. Rgb stands for the red, blue and green values that are used to create a colour. Values can range between 0 and 255.

If the 3 values are the same then the colour will range from black (colour zero) to white (255 255 255) with shades of grey in between.

Using 3 different colours ceates 255 x 255 x 255 possible colours.

Cls clears the screen and fills it with the given colour.

Blit copies one rectangular area of he screen to another. The rectangles may be the same size. If the destination rectangle is larger than the source then the image will be stretched. If the destination image is smaller then the image will be shrunk.

The image can be flipped or inverted.


Sprites

A sprite is a image that can be moved around the screen. The image is typically created with a paint program. The image file can be a windows bitmap (.bmp) file.

loadsprite filename$ n loads a sprite bitmap into memory and assigns it a number. This speeds up the use of a sprite as once it has been loaded into memory it doesn't have to be reloaded each time it is used.

Sprites can be placed anywhere on the screen. places sprite at position 100 200. All sprites use masks. A mask file is a bitmap file that has the same dimensions as the image file. The mask file has only 2 colours, white and black. The mask file has black where the image file has white and vice versa.
Image Mask
When a sprite is placed its mask is automatically placed at the same location. This allows images to be different shapes. Without masking, all bitmap graphics would be rectangular shaped.

A sprite can be made to move automatically by setting its dx and dy values. (The d is short for difference.)

To make a sprite move diagonally change both the dx nd the dy values.

To make a sprite move slowly make the dx and/or dy values small (1 or -1).

To make a sprite move faster use larger dx and dy values. (say 4 or 8)

If the dx and dy values are too large then the movement may become jerky.

You might want something to happen when a sprite collides with another sprite. This could be done by using SpriteCol with an if statement.

Sprites move every time the screen is updated.

Smaller sprites and sprites composed of fewer colours will move faster.

Sprites do not have to move. Sprites that don't move can be used in the background. For example they could be used for platforms in a platform game.

Sprites can be made visible or invisible by using SpriteOn and SpriteOff.

Different sprites can use the same image.

A sprite can use different images. This is used to create animation.

Refresh can be used to cause the screen to be redrawn.


Scrolling

The screen can be scrolled left, right, up or down by changing the dx and dy values.

Changing both together will create a diagonal scroll.

Tiles and sprites will scroll with the screen.

Screens can be of different sizes.

Tiles

Tiles are square blocks that can b used to build the background. Tiles use a bitmap (.bmp) file from which square blocks are copied to the screen.

A map file contains data representing a two dimensional map.

The tiles allow different types of terrain to fit together.

For example, imagine there is a map consisting of land and sea. The letter "a" in the map file represents land while the letter "b" represents sea.

Say part of the map file looks like this: bbb bab bbb

Each letter in the map file corresponds to 4 tiles which fit together in a 2x2 square. The program automatically selects the 4 tiles needed for each square in the map. The 4 tiles it selcts will depend on the adjacent squares.

LoadTiles loads a bitmap into memory that will be used for tiles. LoadMap loads a map that will use the tiles. loadtiles and loadmap must always be used together. The same tiles bitmap can be used with different maps. loadmap gives the starting position of the map. TileScreen fills the screen with tiles.


Events

KeyPress can be used to tell what the last key pressed was.

MouseButton gives what the last mousebutton pressed was.

MouseX and mousey give the co-ordinates of the mouse.

Zones are rectangular areas on the screen. Zones can be created to detect where the mouse or a sprite is.

Wait can be used to pause a program for the given number of milliseconds.

SpriteCol can be used to see if one sprite has collided with another. SpriteCols can be used to see if one sprite has collided with any other.


Sound


Maths

Cos, Sin and Tan return trigometric values.

Abs returns the absolute value of a number.

Sgn returns the sign of a number (-1 or 1).

Power gives the power of x to y.

Sqr gives the square root of a number.

Rnd generates a random decimal point number between 0 and 1


File functions

CurrentDate returns the current date.

CurrentDir returns the current directory.


DEBUG

When in debug mode you can step through your program one line at a time. Selecting the Debug menu will check that menu item and put the program in debug mode.

Step Into

Takes you to the next program line.

Step Over

Takes you to the next program line, but does not enter a new function. In most cases Step Into and Step Over are the same.

Step Out

Takes you out of a function.

Run To Cursor

This takes you to where the cursor is in the code window. Watches allows you to see the current values of all your program variables etc. as you step through the program.

Options

You can change the fonts of the various windows. You can change the output screen from small to full screen.

Help

This menu displays the help files.

Tools

Sprite Editor

The Sprite Editor allows you to create sprites. A sprite is stored as a windows .bmp file. A sprite is an image that can move on the screen. Each sprite needs a mask. Without a mask all images would appear rectangular in shape. The mask allows an image to be any shape.

Masks are only 2 colours, black and white. The colour black in the sprite corresponds to the colour white in the mask. all other colours correspond to black in the mask.

Sprites are not drawn immediately to the front screen. Any tiles are drawn to the background screen. Sprites (and their masks) are drawn on top of the background. The background screen is then copied to the foreground screen.

This is done to prevent flicker. If sprites were drawn immediately to the front screen then there would be considerable flicker.


Sound Editor

The Sound Editor allows you to test a sound to see what it sounds like.

Tile Editor

The Tile Editor allows you to create tiles which are blocks that can be used to build the backgrounds of your screens.

Sprites can move over tiles.

The Tile Editor is not functional yet.


Ascii codes

Each character has a corresponding Ascii code which is a number between 0 and 255. Characters represented by ascii codes include digits (0-9), uppercase letters (A-Z), lowercase letters (a-z), other printable characters (!@#$%^&*()_+ etc.) and nonprintable characters such as the Enter key, escape key, cursor keys, function keys etc.

  • Chr can give you the character for the given ascii code.
  • Asc can give you the ascii code of the given character.

    Ascii Codes

        00             |    01             |    02             |    03             |
        04             |    05             |    06             |    07             |
        08             |    09             |    10             |    11             |
        12             |    13             |    14             |    15             |
        16             |    17             |    18             |    19             |
        20             |    21             |    22             |    23             |
        24             |    25             |    26             |    27             |
        28             |    29             |    30             |    31             |
        32              |    33         !    |    34         "    |    35         #    |
        36         $    |    37         %    |    38         &    |    39         '    |
        40         (    |    41         )    |    42         *    |    43         +    |
        44         ,    |    45         -    |    46         .    |    47         /    |
        48         0    |    49         1    |    50         2    |    51         3    |
        52         4    |    53         5    |    54         6    |    55         7    |
        56         8    |    57         9    |    58         :    |    59         ;    |
        60         <    |    61         =    |    62         >    |    63         ?    |
        64         @    |    65         A    |    66         B    |    67         C    |
        68         D    |    69         E    |    70         F    |    71         G    |
        72         H    |    73         I    |    74         J    |    75         K    |
        76         L    |    77         M    |    78         N    |    79         O    |
        80         P    |    81         Q    |    82         R    |    83         S    |
        84         T    |    85         U    |    86         V    |    87         W    |
        88         X    |    89         Y    |    90         Z    |    91         [    |
        92         \    |    93         ]    |    94         ^    |    95         _    |
        96         `    |    97         a    |    98         b    |    99         c    |
        100        d    |    101        e    |    102        f    |    103        g    |
        104        h    |    105        i    |    106        j    |    107        k    |
        108        l    |    109        m    |    110        n    |    111        o    |
        112        p    |    113        q    |    114        r    |    115        s    |
        116        t    |    117        u    |    118        v    |    119        w    |
        120        x    |    121        y    |    122        z    |    123        {    |
        124        |    |    125        }    |    126        ~    |    127            |
        128        €    |    129            |    130        ‚    |    131        ƒ    |
        132        „    |    133        …    |    134        †    |    135        ‡    |
        136        ˆ    |    137        ‰    |    138        Š    |    139        ‹    |
        140        Œ    |    141            |    142        Ž    |    143            |
        144            |    145        ‘    |    146        ’    |    147        “    |
        148        ”    |    149        •    |    150        –    |    151        —    |
        152        ˜    |    153        ™    |    154        š    |    155        ›    |
        156        œ    |    157            |    158        ž    |    159        Ÿ    |
        160             |    161        ¡    |    162        ¢    |    163        £    |
        164        ¤    |    165        ¥    |    166        ¦    |    167        §    |
        168        ¨    |    169        ©    |    170        ª    |    171        «    |
        172        ¬    |    173        ­     |    174         ®   |    175        ¯    |
        176        °    |    177        ±    |    178        ²    |    179        ³    |
        180        ´    |    181        µ    |    182        ¶    |    183        ·    |
        184        ¸    |    185        ¹    |    186        º    |    187        »    |
        188        ¼    |    189        ½    |    190        ¾    |    191        ¿    |
        192        À    |    193        Á    |    194        Â    |    195        Ã    |
        196        Ä    |    197        Å    |    198        Æ    |    199        Ç    |
        200        È    |    201        É    |    202        Ê    |    203        Ë    |
        204        Ì    |    205        Í    |    206        Î    |    207        Ï    |
        208        Ð    |    209        Ñ    |    210        Ò    |    211        Ó    |
        212        Ô    |    213        Õ    |    214        Ö    |    215        ×    |
        216        Ø    |    217        Ù    |    218        Ú    |    219        Û    |
        220        Ü    |    221        Ý    |    222        Þ    |    223        ß    |
        224        à    |    225        á    |    226        â    |    227        ã    |
        228        ä    |    229        å    |    230        æ    |    231        ç    |
        232        è    |    233        é    |    234        ê    |    235        ë    |
        236        ì    |    237        í    |    238        î    |    239        ï    |
        240        ð    |    241        ñ    |    242        ò    |    243        ó    |
        244        ô    |    245        õ    |    246        ö    |    247        ÷    |
        248        ø    |    249        ù    |    250        ú    |    251        û    |
        252        ü    |    253        ý    |    254        þ    |    255        ÿ    |
    

    Error messages

    overflow
    overflow

    if without endif
    if without endif

    if without EndIf
    if without EndIf

    Else without EndIf
    Else without EndIf

    endif must be by iself
    endif must be by iself

    While without Wend
    While without Wend

    Wend without While
    Wend without While

    Var not followed by name
    needs to appear on a line by itself

    if or elseif must be followed by test.
    if or elseif must be followed by test.

    cannot be at the start of a line
    cannot be at the start of a line

    cannot be at the end of a line
    cannot be at the end of a line

    needs to appear on a line by itself
    needs to appear on a line by itself

    while must be followed by test
    while must be followed by test

    wend must be by iself
    wend must be by iself

    fn must be followed by name
    fn must be followed by name

    fn cannot be in another function
    fn cannot be in another function

    constants need to be assigned
    constants need to be assigned

    unknown
    unknown

    is not an assignment
    is not an assignment

    is not followed by operator
    is not followed by operator

    Unknown name
    Unknown name

    has too few arguments
    has too few arguments

    A name cannot be a keyword
    A name cannot be a keyword

    name cannot start with a number
    name cannot start with a number

    Illegal name
    Illegal name