Runtime Revolution
 
Articles Other News

Cannonballs, Part 6

by Robert Cailliau

Cannonball Tutorial! Part 1.1 | Part 1.2 | Part 2.1 | Part 2.2 | Part 3.1 | Part 3.2
Part 4.1 | Part 4.2 | Part 5.1 | Part 5.2 | Part 6.1 | Part 6.2

This is what we learned in the Cannon tutorial.

The Message Box

The message box is a development tool that lets you type single statements to see what happens and try out something without having to create an object and a handler.

Graphics and images

Images are objects like photos that are generally made outside Revolution. They are bitmapped graphics.

Graphics are objects within Revolution, they have graphic properties such as points. They are vector graphics.

Graphics and images cn be created and deleted.

Operators: is, &

We saw one use of the is operator:

if there is no image ...

which lets you test the existence of an object. Technically, the operator is all three words together: there is no. But is is used in quite a few of these operators: there is, is a, is not a, ...

We used & to glue character strings together (concatenation).

Items

An item is a part of a list. Items are separated by commas (though this can be changed).

Location, layer, point and rect

All objects have a location loc and each object has its own layer on the card on which it sits. Higher layers cover what is on lower layers. Layer number can be set in the inspector.

A point is two numbers sepatated by a comma.

A rect is four numbers separated by commas, giving the top-left and bottom-right points of a rectangle.

Controls: Scrollbars

Scrollbars have a graphic size, but they also have values for the start and end position of the thumb (the button that you slide). They get the message scrollbardrag when you move the thumb.

Formal parameters

Parameters to handlers are values that the handler is given from the outside. They are also called formal parameters.

Controls: Fields

All controls have properties that let you decide how they look: border, transparency, background colour and so on. You can set them in the inspector, but also by program code.

Coordinate System

Coordinates in screen graphics have the y-axis pointing down. This creates confusion as calculations are normally done with the y-axis pointing up. There are several tricks to get it right, but none are intuitive and errors are frequently made.

Statements

You learned about:

  1. repeat,
  2. the difference between put and set,
  3. add and subtract,
  4. wait,
  5. putting more than one statement on a line,
  6. sending a message with send,
  7. return to give back values,
  8. comments ("--").

Physics and motion simulation

Simulation is done by:

  1. repeatingly making small changes,
  2. each time calculating what the changes should be,
  3. taking into account the changed situations,
  4. remembering what needs to be remembered for the next calculation.

Debugging

You can let the program go step by step and watch what happens to the variables.

You do this by setting breakpoints and using the variable watcher.

Trigonometric functions and radians

While this is maths more than programming, it was necessary to mention it. A circle is 360º around, or 2 radians. A radian is the angle that corresponds to a distance of one radius measured along the circumference:

Using fields as labels

Label fields are useful to place fixed text on a card. They are nothing special, they are normal fields for which the opacity has been switched off.

Custom properties

Objects can be given properties that you create. Custom properties are of two kinds:

  1. simple named containers that can get a value,
  2. getprop handlers that compute a value when needed.

The getprop handler type lets you do object-oriented programming.

Avoiding numbers in the code

We used the top of graphic "Grass" rather than the number 480. If we decide to make the Grass graphic less high, our program will still work. Had we used the number 480, we would have to change that too.

Emergency brake

Press command-period (control-period in Windows) to stop a program that has "run away".

Test on inequality

Do not test numbers for equality unless you are certain that they are whole numbers.

Drawing in images

Images can be changed by drawing operations, of which we saw only dragging the line tool.

Rounding

Positions are whole numbers of pixels. Revolution will truncate fractional numbers if they are used for positions, therefore using the round() function gives better results.

Cannonball Tutorial! Part 1.1 | Part 1.2 | Part 2.1 | Part 2.2 | Part 3.1 | Part 3.2
Part 4.1 | Part 4.2 | Part 5.1 | Part 5.2 | Part 6.1 | Part 6.2

 
©2008 Runtime Revolution Ltd, 15-19 York Place, Edinburgh, Scotland, UK, EH1 3EB.
Questions? Email info@runrev.com for answers.