Diary of an Amiga fanatic

Category Archives: Amos Professional

Time for part 2 in our basics tour. This time we are going to talk about Procedures. Procedures will allow you to create separate blocks of code that perform a specific task. Let’s say you need to perform certain tasks often. Instead of writing the same code (a smart person would copy and paste it of course) every time you could write it once as a Procedure and just call upon that Procedure whenever you need it. Another benefit is that your code will be more easy to maintain and read. Let’s take our example from our first tutorial and turn it in to a Procedure.

Procedure XPRINTING
x=0
While X<11
Inc X
Print X
Wend
Print “We left the loop!”
End Proc

As you can see we only added “Procedure XPRINTING” and “End Proc” to our code. The first line gave our Procedure a name and the second will indicate the end of the Procedure. Just having this in your code will not actually execute it. You need to call the Procedure in order for it to execute. We call it by just mention it’s name:

>XPRINTING

Another way of calling it is:

>Proc XPRINTING

The same rules that apply for the name of a variable apply for the name of a Procedure. Another near thing about Procedures is that you can close them so only the name will show but not all the code inside. Make sure the cursor is on the Procedure line and press the F9 key to fold/unfold it. You can also select the [Procedures] option from the [Editor] menu and trigger the [Open/Close] option.

I hate to do this but now I am going to get a bit technical and even maybe scare you. The variable X (X=0) in our example without being wrapped neatly in a Procedure is different than being wrapped in the Procedure. Outside the Procedure we call X a global Variable and inside the Procedure a local variable. Let’s say you change X inside the Procedure it would not effect Variable X that is outside the Procedure and the other way around. You can of course imagine a scenario in which you would like to use X in a way that if you change it outside the Procedure X inside the Procedure X will also change and the other way around. This is possible but for now I will leave it at this and discuss it in another tutorial.

Let’s use our new Procedure to learn something new. Have a look at the below code.

Our Procedure

Procedure XPRINTING
X=0
While X<11
  Inc X
  Print X
Wend
Print "We left the loop!"
End Proc

Print "Click the left mouse button to execute the Procedure"
Print "Click the right mouse button to exit"

Do
 M=Mouse Click
 If M=1 Then Proc XPRINTING
 If M=2 Then Exit
Loop
Print "We have left our program"

I pressed the left mouse button first to execute our Procedure and after this press the right mouse button to exit our program. The below screenshot will show you how it will look like.

Output!

The newly added code (we know what the two PRINT statements do) is the Do – Loop part. If you understood the While – Wend control structure you will also understand the Do – Loop control structure. The Do – Loop control structure will repair what is inside it’s structure forever. We can leave the Do – Loop control structure by using the “Exit” command which you of course already spotted. It is actually really simple what we are doing in the D0 – Loop control structure. We have it check for a left and right mouse click and for each click it will do something. The left click will execute the Procedure and the right click will exit the Do – Loop control structure.

The “M=Mouse Click” command will check if the left or right mousse button was clicked.

It will store the value in M. There are three values as we can see below.

Bit 1 Single test for left mouse button
Bit 2 Single test for right mouse button
Bit 3 Single test for third mouse button, if available

All we need to do is check the value of M and execute the corresponding action. This is what we do with

 If M=1 Then Proc XPRINTING
 If M=2 Then Exit

If M has the value of 1 which is the left click we will execute our Procedure. If M has the value of 2 which is the right click we will exit our Do-Loop control structure and with it end our program. I hope everything is clear enough to understand it. That’s it for this time and I will see you next time.


Unlike my OS4.x programming tutorials in C I will start with the basics for Amos Professional. This, and further, tutorials are aimed at the absolute beginners. People that really want to start programming but want to start with something easy (cue Amos!) and need a lot of guidance. Once you master Amos you can move on to something else. Why Amos? Is it not a dead language? Absolutely not! I am actually using it to create a new disk magazine for the classic Amiga’s. What makes Amos so great is that it will allow you to learn programming the easy way and get better along the way. No 100 lines of code to open a screen but just one line only in Amos. It takes away the difficult part so you you won’t be scared away and stick around. Are you still with me? Good! Let’s get started….

As a programmer you should put comments in your code to describe what it is doing. You might know what it does when you write the code but several months later you might not. Also if someone else is reading your code they can understand what is going on. Many times I had discovered how to fix something and not provide comments only to discover at a later stage that I had no clue what it was actually doing. There are two ways of providing comments in your code:

Rem This next line of code will make me rich!

‘ This next line of code will make me rich!

As you can see we can use “Rem” in front of our comments or the apostrophe ‘.

Now I am going to show you an example that will address a lot of points in one time. Don’t worry if you looked at it and don’t understand a thing.

x=0
While X<11
Inc X
Print X
Wend
Print “We left the loop!”

Our first example!

The run our example we can press F1 or select “Run” from the “Project” menu in Amos Professional.

What does example does is print the numbers 0 till 10 on the screen and once it has reached 11 it will print “We left the loop!”.

The first line “x=0” will set x to 0. We call X a variable. A variable means that it’s value can change. This will make sense in short moment when we discuss the rest of the example. Just to complete it you need to know that the name of a variable has to begin with a letter and cannot begin with a number. What is also not allowed is that the name starts with letters that make up one of the Amos Professional commands. I will show you….

FRIDAY=1

The above is allowed.

1FRIDAY= 1

The above is not allowed since it starts with a number.

FRIDAYPRINT=1

The above is allowed.

PRINTFRIDAY=1

The above is not allowed since the first part makes up the Amos Professional command “PRINT”.

Next we reach the “While – Wend” part. While – Wend will repeat a group of instructions till a certain condition is true. For example While – Wend will instruct your wife to go shopping till the wallet is empty. In our example While – Wend will print the value of X till X has reached the value 11. The instruction “While X<11” is taking care of this. The part “X<11” means till the value of X is less (<) than 11. The command “Inc X” in our While – Wend statement will increase the value of X each time with one. Remember I said earlier on that the value of a variable can change? In our example the value of our variable X will change. The command “Print X” will print the value of X. Once X has reached the value 11 our program will leave the While – Wend statement and execute our last part in which it will print “We left the loop!”.

So what do you think? Easy to understand? Please let me know if it is not clear or you have questions left. That’s all for now. Next time we will go a bit deeper but still maintain that level of easiness.